0

I want to run

  • a shell script restore
  • as postgres user
  • from php script (the user name is php)
  • using sudo

the script will have few lines of code, something like

dropdb <database name>
psql -c "create database <database name> with encoding 'unicode';" -U edutemplate1
psql -d <database name> -f edu.hourly.sql 
  • what would be the sudo command syntax to run the script restore
  • what would be the sudoers syntax to allow php user to run restore script as postgres user?
1
  • Second part of question will be better asked at serverfault Commented Mar 28, 2011 at 1:57

1 Answer 1

2

The command is absolutely the same as you do in console:

sudo -u db1inst1 /path/to/script.sh

Or even:

system('sudo -u db1inst1 /path/to/script.sh');

or

`sudo -u db1inst1 /path/to/script.sh`
Sign up to request clarification or add additional context in comments.

1 Comment

With a default sudoers, that's going to run it as root, not as php.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.