What's a good way of running a shell script as a different user. I'm using Debian etch, and I know which user I want to impersonate.
If I was doing it manually, I would do:
su postgres
./backup_db.sh /tmp/test
exit
Since I want to automate the process, I need a way to run backup_db.sh as postgres (inheriting the environment, etc)
Thanks!
-(or--login) together with--command, -cdoesn't actually start a login session, because-calways forces a non-login shell. – JeanMertz May 01 '13 at 13:46- postgressshould appear at the end of the command. From the man page:When - is used, it must be specified before any username. For portability it is recommended to use it as last option, before any username. The other forms (-l and --login) do not have this restriction.– jonny May 02 '17 at 14:45www-datauser ? – Chang Zhao Aug 30 '21 at 21:56