LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   run command as user (https://www.linuxquestions.org/questions/linux-newbie-8/run-command-as-user-349726/)

BFEINZIMER 08-03-2005 05:53 PM

run command as user
 
hey

quick question

in my /etc/rc.d/rc.local file, i am adding a command to start my teamspeak server on the boot of my webserver....everything ok, right?

BUT, i dont want to run it as root, ive configured this user "tss" to be able to run the teamspeak server with the command:

sh /home/httpd/vhosts/bfserver.com/games/tss2_rc2/teamspeak2-server_startscript start

which is in the file which has:

#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local
sh /home/httpd/vhosts/bfserver.com/games/tss2_rc2/teamspeak2-server_startscript start


SO.....

how can i run this at startup as my user tss instead of root?

thanks

BFEINZIMER 08-03-2005 06:01 PM

hah, also so the server shutsdown cleanly at a reboot, where would i put the stop command for the teamspeak server?

tuxdev 08-03-2005 06:09 PM

for doing stuff as other users without logging in, I think the command is "su user -c command". For shutting down the server, put something in the equavalent of /etc/rc.d/rc.0 on FC.

BFEINZIMER 08-03-2005 06:15 PM

Quote:

Originally posted by tuxdev
for doing stuff as other users without logging in, I think the command is "su user -c command". For shutting down the server, put something in the equavalent of /etc/rc.d/rc.0 on FC.
thanks for that but:

http://www.gsp.com/cgi-bin/man.cgi?section=1&topic=su

on there it says it would ask for a password...its a remote webserver so i wouldent be able to type one in...how would i handle this??

and im on redhat9...so would the file still be rc.0?

oot 08-03-2005 06:17 PM

Root can run "su <someuser>" without having to enter a password. If you just want to execute one command su'd instead of starting a shell logged in as that user, you use the -c option. So it'd be 'su -c "<command to run>" <user>'.

As for shutdown, most distributions have scripts that are used when you change runlevels (shutdown is changing to runlevel 0, reboot is changing to runlevel 6). So you need to find where Red Hat stores scripts for these runlevels, and add the command to stop the server there. I'm not 100% sure, but I think if you create /etc/rc.d/rc0.d/K??teamspeak, and /etc/rc.d/rc6.d/K??teamspeak (replace ?? with numbers... the scripts in the directory will execute in the order they're numbered), and put the commands in there (make sure that the files are executable), that might do it.

BFEINZIMER 08-03-2005 06:20 PM

ok so i tried running this from the terminal as user tss:

su tss -c sh /home/httpd/vhosts/bfserver.com/games/tss2_rc2/teamspeak2-server_startscript.sh start

it then asked for my password, which i typed in, then it prompts:


sh-2.05b$ (cursor)

and i enter in /home/httpd/vhosts/bfserver.com/games/tss2_rc2/teamspeak2-server_startscript.sh start, and it starts the server....

so i need a way to automate this

BFEINZIMER 08-03-2005 06:29 PM

Quote:

Originally posted by oot
Root can run "su <someuser>" without having to enter a password. If you just want to execute one command su'd instead of starting a shell logged in as that user, you use the -c option. So it'd be 'su -c "<command to run>" <user>'.

As for shutdown, most distributions have scripts that are used when you change runlevels (shutdown is changing to runlevel 0, reboot is changing to runlevel 6). So you need to find where Red Hat stores scripts for these runlevels, and add the command to stop the server there. I'm not 100% sure, but I think if you create /etc/rc.d/rc0.d/K??teamspeak, and /etc/rc.d/rc6.d/K??teamspeak (replace ?? with numbers... the scripts in the directory will execute in the order they're numbered), and put the commands in there (make sure that the files are executable), that might do it.

so if i just make the file and insert the command it will run, awesome......

and i understant if im asking from root to run as tss i shouldent need a password...but read the last post I made, and see that it requireds a 2nd command after the first..hmmmm

BFEINZIMER 08-03-2005 06:34 PM

hmm now i get this when running root

[root@BFSERVER root]# su tss -c sh /home/httpd/vhosts/bfserver.com/games/tss2_rc2/teamspeak2-server_startscript start
bash: /root/.bashrc: Permission denied
sh-2.05b$

BFEINZIMER 08-04-2005 01:40 AM

bumpatize me captin

BFEINZIMER 08-24-2005 10:21 PM

cmon guys please.....lol


All times are GMT -5. The time now is 04:57 AM.