Switch user Shell Script

Bill Campbell linux-sxs
Mon Jun 18 09:49:25 PDT 2007


On Mon, Jun 18, 2007, RAVIKIRAN_GUNISETTI wrote:
>
>Hi, 
>Iam new to the shell scripting & need help ..
>
>
>My Scenario: [Zimbra Mail Server]
>``````````````````````````````````````````````````````
>I have to write a shell script which changes the user from " root " to
>"zimbra" using 'su - zimbra'
>Then perform certain tasks & then logout from the 'zimbra user'
>
>
>Now i can successfully log into 'zimbra' but the commands that i have
>written after the 'su - zimbra' doesnot get recognized by the BASH SHELL &
>thus my shell-script fails.
>
>I tried using '|' but no luck. 
>
>My Sample Script is
>``````````````````````````````
>su - zimbra
>zmcontrol status > zm_status.txt
>exit

I would suggest using ``sudo'' rather than ``su''.

	sudo -u zimbra scriptname

This will require that you set up an appropriate entry in the
``sudoers'' file (usually /etc/sudoers) allowing root to sudo to
the zimbra user.  I thing this would be something like:

root ALL = NOPASSWD: path_to_scriptname

Bill
--
INTERNET:   bill at Celestial.COM  Bill Campbell; Celestial Software LLC
URL: http://www.celestial.com/  PO Box 820; 6641 E. Mercer Way
FAX:            (206) 232-9186  Mercer Island, WA 98040-0820; (206) 236-1676

Government spending?  I don't know what it's all about.  I don't know
any more about this thing than an economist does, and, God knows, he
doesn't know much.
		-- Will Rogers



More information about the Linux-users mailing list