| | |
How to su properly in a shell script
![]() |
•
•
Join Date: Nov 2004
Posts: 8
Reputation:
Solved Threads: 0
Hello,
I have written a script to automate a software install. I am running the script as root, but need to su to another user to configure and complile the program properly. Whenever I do the shell script su's to the user properly but the scripts stops executing until I exit out of the new shell that su put me into. The following is an example of my script.
echo -e "\033[1m \n\t Installing courier-imap... \033[0m"
sleep 2
cd /var/src
tar -xjf tar/courier-imap-2.2.2.20040207.tar.bz2
cd courier-imap-2.2.2.20040207
# build as vpopmail
chown -R vpopmail:vchkpw ../courier-imap-2.2.2.20040207
su - vpopmail
./configure --with-redhat
I have also tried using the following to stay in the same shell and preserve the environment:
su - -m -p vpopmail
Does anyone have any thought as to how I can successfully SU and keep the script running?
Thanks,
Stephen
I have written a script to automate a software install. I am running the script as root, but need to su to another user to configure and complile the program properly. Whenever I do the shell script su's to the user properly but the scripts stops executing until I exit out of the new shell that su put me into. The following is an example of my script.
echo -e "\033[1m \n\t Installing courier-imap... \033[0m"
sleep 2
cd /var/src
tar -xjf tar/courier-imap-2.2.2.20040207.tar.bz2
cd courier-imap-2.2.2.20040207
# build as vpopmail
chown -R vpopmail:vchkpw ../courier-imap-2.2.2.20040207
su - vpopmail
./configure --with-redhat
I have also tried using the following to stay in the same shell and preserve the environment:
su - -m -p vpopmail
Does anyone have any thought as to how I can successfully SU and keep the script running?
Thanks,
Stephen
Ever thought about sudo?
It will allow you to execute single commands as a user without having to drop into the shell of that user. You could even run sudo, and point it to another shell script that contains all of the commands you need it to run, so you could make that script stay somewhat compact.
It will allow you to execute single commands as a user without having to drop into the shell of that user. You could even run sudo, and point it to another shell script that contains all of the commands you need it to run, so you could make that script stay somewhat compact.
Alex Cavnar, aka alc6379
•
•
Join Date: Apr 2009
Posts: 1
Reputation:
Solved Threads: 0
•
•
•
•
Ever thought about sudo?
It will allow you to execute single commands as a user without having to drop into the shell of that user. You could even run sudo, and point it to another shell script that contains all of the commands you need it to run, so you could make that script stay somewhat compact.
Use -t option in ssh
•
•
Join Date: Aug 2007
Posts: 165
Reputation:
Solved Threads: 18
•
•
•
•
... Does anyone have any thought as to how I can successfully SU and keep the script running?echo -e "\033[1m \n\t Installing courier-imap... \033[0m" sleep 2 cd /var/src tar -xjf tar/courier-imap-2.2.2.20040207.tar.bz2 cd courier-imap-2.2.2.20040207 # build as vpopmail chown -R vpopmail:vchkpw ../courier-imap-2.2.2.20040207 su - vpopmail ./configure --with-redhat
Shell Scripting Syntax (Toggle Plain Text)
su -c "./configure --with-redhat" - vpopmail
You can execute the commands one at a time, or you can put them in another shell script and have su() execute that shell script.
![]() |
Similar Threads
- load-intensive shell script (Shell Scripting)
- shell script beautifier (Shell Scripting)
- Problem with variables in Windows shell script (Windows NT / 2000 / XP)
- Help with shell script to auto gzip a .sql dump after backup (Shell Scripting)
Other Threads in the Shell Scripting Forum
- Previous Thread: 1500 static html pages into mediawiki format
- Next Thread: how to add comma separated fields to a text column?
| Thread Tools | Search this Thread |






