Q:

Having trouble running a command as another user on Ubuntu

I'm using Ubuntu 14.04.  When logged in as root, I'm tryhing to run a command as anotehr (postgres).  However, it is failing
root@remotebox:/home/rails/myproject# su - postgres 'pg_upgradecluster 9.3 main'
-su: pg_upgradecluster 9.3 main: No such file or directory

What am I doing wrong? 

A:

You're trying to pass 'pg_upgradecluster 9.3 main' to the default shell for postgres user.
Depending on postgres user configuration this may mean to execute 'pg_upgradecluster 9.3 main' file in postgres PATH, and this is the reason you get a "No such file or directory error".
Try pass the argument as a command (-c):
su - postgres -c 'pg_upgradecluster 9.3 main'

as a shell:
su - postgres -s /path/to/pg_upgradecluster -- 9.3 main

or to explicit choose the shell:
su - postgres -s /bin/bash -- -c 'pg_upgradecluster 9.3 main'

