User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 422,371 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,517 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser: Programming Forums
Views: 20976 | Replies: 1
Reply
Join Date: Nov 2004
Posts: 8
Reputation: stharmon is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
stharmon stharmon is offline Offline
Newbie Poster

How to su properly in a shell script

  #1  
Nov 23rd, 2004
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2003
Location: Nashville, TN
Posts: 2,333
Reputation: alc6379 has a spectacular aura about alc6379 has a spectacular aura about alc6379 has a spectacular aura about 
Rep Power: 11
Solved Threads: 102
Colleague
alc6379's Avatar
alc6379 alc6379 is offline Offline
Cookie... That's it

Re: How to su properly in a shell script

  #2  
Dec 2nd, 2004
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.
Alex Cavnar, aka alc6379
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Shell Scripting Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Shell Scripting Forum

All times are GMT -4. The time now is 8:20 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC