I have a bash script that uses sudo a few times. There's a couple of strange points about it though.
- It asks me for my password a few seconds after I've already entered it for a previous command.
- The second time I enter my password, it's echoed to the display.
Here's the relevant bits of the script.
sudo service apache2 stop drush sql-dump --root="$SITE_DIR" --structure-tables-key=svn --ordered-dump | grep -iv 'dump completed on' | sudo tee "$DB_DIR/${SITE_NAME}.sql" > /dev/null sudo svn diff "$DB_DIR" | less sudo svn commit -m "$MESSAGE" "$DB_DIR" sudo service apache2 start The first password is to stop apache, and it works as expected. As mentioned, the sudo tee doesn't 'remember' that I have elevated privileges, asks for the password again, and echoes it to the screen. Given that tee is all about echoing to screen, I've played around a little with simple scripts which have | sudo tee, and they all work as expected.
Edit: I looked into the drush command itself, and it's a bash file that calls PHP using exec. This sounds like it might have potential - any ideas? Here's the line from drush.
exec php $SCRIPT_PATH --php=`which php` "$@" Edit2: Was looking up something to do with Ruby scripts and came across this post about elevated privileges in scripts from serverfault.
sudo tee... is that what you meant?