You are not logged in.
Pages: 1
I want to run the following script called "backup":
#!/bin/bash
sudo -u postgres "pg_dump -Fc davical >davical.pgdump"
But when I run it, the error appears:
sudo: pg_dump -Fc davical >davical.pgdump: command not found
Anyone know what I am doing wrong?
Thanks!
Last edited by awayand (2012-03-24 12:53:21)
Offline
I'm not sure you can have redirection inside a command string like that.
I suspect you could put the command string in it's own script, or perhaps in a function within the same script, then use sudo to call the other script or function.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Thanks for the tip! Now it works:
sudo -u postgres bash -c "pg_dump -Fc davical >davical.pgdump"
Offline
# Check for admin rights. If user is not an admin user, exit the script
if [ $UID != 0 ]
then
echo "You need to be root to run this script! Exiting..."
exit
fi
This snippet checks if you've sudo-ed it (or ran as root). All subsequent commands can be coded without sudo.
Last edited by foppe (2012-03-24 17:07:30)
Offline
Pages: 1