LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-03-2005, 05:53 PM   #1
BFEINZIMER
LQ Newbie
 
Registered: Jan 2005
Location: La Mirada, CA, USA
Distribution: Fedora Core 4, Red Hat 9
Posts: 23

Rep: Reputation: 15
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
 
Old 08-03-2005, 06:01 PM   #2
BFEINZIMER
LQ Newbie
 
Registered: Jan 2005
Location: La Mirada, CA, USA
Distribution: Fedora Core 4, Red Hat 9
Posts: 23

Original Poster
Rep: Reputation: 15
hah, also so the server shutsdown cleanly at a reboot, where would i put the stop command for the teamspeak server?
 
Old 08-03-2005, 06:09 PM   #3
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,014

Rep: Reputation: 115Reputation: 115
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.
 
Old 08-03-2005, 06:15 PM   #4
BFEINZIMER
LQ Newbie
 
Registered: Jan 2005
Location: La Mirada, CA, USA
Distribution: Fedora Core 4, Red Hat 9
Posts: 23

Original Poster
Rep: Reputation: 15
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?
 
Old 08-03-2005, 06:17 PM   #5
oot
Member
 
Registered: Dec 2002
Distribution: Slackware 12.0
Posts: 240

Rep: Reputation: 30
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.
 
Old 08-03-2005, 06:20 PM   #6
BFEINZIMER
LQ Newbie
 
Registered: Jan 2005
Location: La Mirada, CA, USA
Distribution: Fedora Core 4, Red Hat 9
Posts: 23

Original Poster
Rep: Reputation: 15
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
 
Old 08-03-2005, 06:29 PM   #7
BFEINZIMER
LQ Newbie
 
Registered: Jan 2005
Location: La Mirada, CA, USA
Distribution: Fedora Core 4, Red Hat 9
Posts: 23

Original Poster
Rep: Reputation: 15
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
 
Old 08-03-2005, 06:34 PM   #8
BFEINZIMER
LQ Newbie
 
Registered: Jan 2005
Location: La Mirada, CA, USA
Distribution: Fedora Core 4, Red Hat 9
Posts: 23

Original Poster
Rep: Reputation: 15
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$
 
Old 08-04-2005, 01:40 AM   #9
BFEINZIMER
LQ Newbie
 
Registered: Jan 2005
Location: La Mirada, CA, USA
Distribution: Fedora Core 4, Red Hat 9
Posts: 23

Original Poster
Rep: Reputation: 15
bumpatize me captin
 
Old 08-24-2005, 10:21 PM   #10
BFEINZIMER
LQ Newbie
 
Registered: Jan 2005
Location: La Mirada, CA, USA
Distribution: Fedora Core 4, Red Hat 9
Posts: 23

Original Poster
Rep: Reputation: 15
cmon guys please.....lol
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
run mount command as user paul_mat Linux - Newbie 1 12-14-2004 06:28 PM
How to run a command on new mail for a user? pembo13 Linux - Networking 0 09-26-2004 07:37 AM
Switch to another user, get his env and run a command 'under his name' ganninu Linux - General 2 05-25-2004 02:26 PM
How do I give a user to run the nice command? badmofo666 Linux - Newbie 3 03-17-2004 07:01 PM
run command as alternate user joeca Linux - General 1 08-06-2003 04:31 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration