LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Shell Script - Change user & run multiple commands (http://www.linuxquestions.org/questions/linux-newbie-8/shell-script-change-user-and-run-multiple-commands-699909/)

ijf99 01-26-2009 05:49 AM

Shell Script - Change user & run multiple commands
 
Hi folks,

(This may be the wrong forum, apologies if it is)

I'm writing a shell script where the user needs to be changed half-way through then some commands are run by this user. I can do this for one command (e.g. su - X -c "echo 'stuff'"), but doing this for more than one command is proving to be a problem - how would I do this?

Many thanks,
Ian

colucix 01-26-2009 06:15 AM

Have you tried to just separate multiple commands with semi-colon?
Code:

# su - username -c "echo 'stuff'; cd /path/to/dir; pwd; ls"
otherwise you can put all the commands into an executable script and run the script as a single command.


All times are GMT -5. The time now is 10:18 AM.