Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Blog | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

su in a script?



"su" will create a new shell with the owner you specify.  In
order to run something as that user, you need to specify:

    su quake3 -c "cd /usr/local/games/quake3; ./linuxq3ded ..."

and pass a single command to "su" to run as user "quake3", or
you can create a second script that has several commands and use:

    su quake3 -c "/usr/local/games/runquakescript"

(runquakescript has the "cd" and the "linuxq3ded" and whatever
commands you need in it.)

Also, if you have environment variables or aliases or anything
else that can be put into the ~quake3/.bashrc (or .profile),
you can use:

    su - quake3 -c "command_to_run"

The " - " tells "su" to run any login/profile/rc startup scripts
for the user "quake3".

-- 
Gordon Keegan, M10-10		Phone: (508) 261-4696
Motorola ING			Fax:   (508) 261-5757
20 Cabot Boulevard
Mansfield, MA 02048		email: lgk011 at dma.isg.mot.com


> Hello agin...its the script guy again
> 
> Im trying to write a script to run an aplication after it su's to a diferent
> user...can this be done?
> 
> right now it stops after it does its su!
> 
> #!/bin/sh
> su quake3
> 
> cd /usr/local/games/quake3
> 
> ./linuxq3ded +set dedicated 2 ...blah..blah
> ----------------
> The script seems to bomb after it su's...it changes to the quake3 user then
> it just sits at the prompt!  I can then enter the comand to run the
> app....but I want it to do the whole thing!
> 
> 
> thnx
> Katz
> 
> -
> Subcription/unsubscription/info requests: send e-mail with
> "subscribe", "unsubscribe", or "info" on the first line of the
> message body to discuss-request at blu.org (Subject line is ignored).
> 


-
Subcription/unsubscription/info requests: send e-mail with
"subscribe", "unsubscribe", or "info" on the first line of the
message body to discuss-request at blu.org (Subject line is ignored).




BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org