exec script as user on boot not root


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting exec script as user on boot not root
# 1  
Old 07-08-2009
Question exec script as user on boot not root

Is there a way to change a process owned by root to be owned by another user. I am interested in finding out if there is a way to put a script in /etc/rc2.d that will start up automatically on reboot that will not be owned by root

This is for security reasons.. The Service that runs on my server recomends that I dont run it as root..
Im at the office right now and I have the script on my home computer, if needed I can post it. But Im merly intressted if its possible and what command exec´s stuff as an assigned user. root -> run startTS.sh as user seb
# 2  
Old 07-08-2009
Hi.

I don't suppose you can change the uid of a running process, but to run something at startup from /etc/rc.d, as a different user, use "su"

Code:
man su

# 3  
Old 07-08-2009
ofc... its always the simplest solution...
Then Ill add
PHP Code:
su seb 
In the beginning of the script so the command that starts the service is run as user seb
For some reason I dident think logging on as a normal user at that stage worked. Kinda stupid now when I think about it. Heh thank you
# 4  
Old 07-08-2009
Within the startup script /etc/rc2.d/Snnnxxxxx execute a script in another directory to do what you want.

Code:
su seb -c "script to be executed"

BTW. On many unixes rc3 is the place to start user applications (not rc2).
# 5  
Old 07-09-2009
Thank you methyl. As you realise this is my first on boot script. I have done a handfull of diffrent scripts that manualy exec when thay are needed..

Ok so I will make a script in /etc/rc2.d/
PHP Code:
su seb -"/home/seb/tss/startservice.sh" 
Did I understand you correct in this matter?
# 6  
Old 07-09-2009
Hi.

Yes, exactly.

I would run it with "su -"

Code:
su - seb -c "/home/seb/tss/startservice.sh"

That way you get seb's environment too.

If you have a method to stop the application when you shutdown, don't forget to create a Knnnnnnn script too.

(the Snnnnn and Knnnnn scripts are often generic...)

Code:
case "$1" in
start )
        startsrc -g ssh
        ;;
stop )
        stopsrc -g ssh
        ;;
* )
        echo "Usage: $0 (start | stop)"
        exit 1
esac

The number you use for your S and K scripts determines the order in which your script is executed, so make sure everything else your application needs (i.e. Oracle, or whatever) is started before you start your application.
# 7  
Old 07-09-2009
If you use "su - seb -c ......" you may need to edit your profile scripts and stop them running commands like "stty" which need a real terminal.

Code:
if [ -t 1 ]
then
      # Do commands which need a terminal
fi

I usually create a set of environment scripts for each application and call the appropriate script from startup scripts and user profiles. This is most useful for database engines such as Oracle.

See "man rc" for an explanation of startup script names etc. . Always test the scripts thoroughly before rebooting the machine. Remember to have a stop "K" script for every start "S" script and to stop in the reverse order you start.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to Switch from Local user to root user from a shell script?

Hi, I need to switch from local user to root user in a shell script. I need to make it automated so that it doesn't prompt for the root password. I heard the su command will do that work but it prompt for the password. and also can someone tell me whether su command spawns a new shell or... (1 Reply)
Discussion started by: Little
1 Replies

2. Shell Programming and Scripting

Switch between root and user in the same script.

I am writing a korn shell script where i need to switch to root in between and again exit from root to normal user and continue other commands. Is that possible to switch between these two in the same script? (1 Reply)
Discussion started by: santosh2626
1 Replies

3. Shell Programming and Scripting

Script Variables Inquiry, Values Okay in Standalone Exec, No-Show in Cron Exec

I have the following bash script lines in a file named test.sh. #!/bin/bash # # Write Date to cron.log # echo "Begin SSI Load $(date +%d%b%y_%T)" # # Get the latest rates file for processing. # d=$(ls -tr /rms/data/ssi | grep -v "processed" | tail -n 1) filename=$d export filename... (3 Replies)
Discussion started by: ginowms
3 Replies

4. Shell Programming and Scripting

How to Login as another user through Shell script from current user[Not Root]

Hi Every body, I would need a shell script program to login as different user and perform some copy commands in the script. example: Supppose ora_toms is the active user ora_toms should be able to run a script where user: ftptomsp pass: XXX should login through and run the commands ... (9 Replies)
Discussion started by: ujjwal27
9 Replies

5. UNIX for Dummies Questions & Answers

Sudo to delegate permission from non-root user to another non-root user

I've been through many threads before i decide to create a separate thread. I can't really find the solution to my (simple) problem. Here's what I'm trying to achieve: As "canar" user I want to run a command, let's say "/opt/ocaml/bin/ocaml" as "duck" user. The only to achieve this is to... (1 Reply)
Discussion started by: canar
1 Replies

6. Shell Programming and Scripting

Need to run a bash script that logs on as a non-root user and runs script as root

So I have a script that runs as a non-root user, lets say the username is 'xymon' . This script needs to log on to a remote system as a non-root user also and call up a bash script that runs another bash script as root. in short: user xymon on system A needs to run a file as root user and have... (2 Replies)
Discussion started by: damang111
2 Replies

7. UNIX for Advanced & Expert Users

/root restore backup exec

Hi we use backup exec to backup our linux servers... question is what if the linux server is corrupted (/root) and doesnt boot up .. how would the backup exec restore /root if the server cant even start? woukld we have to restore to another server then boot into rescue mode and copy across... (0 Replies)
Discussion started by: halacil
0 Replies

8. Shell Programming and Scripting

root user command in shell script execute as normal user

Hi All I have written one shell script for GPRS route add is given below named GPRSRouteSet.sh URL="www.google.com" VBURL="10.5.2.211" echo "Setting route for $URL for GPRS" URL_Address=`nslookup $URL|grep Address:|grep -v "#"|awk -F " " '{print $2}'|head -1` echo "Executing ... (3 Replies)
Discussion started by: mnmonu
3 Replies

9. Shell Programming and Scripting

root executes a script as another user

Hi All, Am using the below command to start my application using the root user su - bin -c "/home/bin/test/start.sh" but am getting the error becaue i have set some environment varibales in bin's .profile when i execute the command start.sh by logging directly into bin account it's... (9 Replies)
Discussion started by: ravi.sri24
9 Replies

10. Shell Programming and Scripting

root executes a script as another user

we have this script that stops, starts and monitor process scheduler. prcs_control. this script runs perfectly when executed by ps_user. we are now creating a new script that will run this script and is executed by root. this script needs to execute the prcs_control as ps_user because root can... (1 Reply)
Discussion started by: tads98
1 Replies
Login or Register to Ask a Question