How would I automate shell script startup during a reboot??
Greetings,
How would I go about having some shell scripts start up during a reboot of a Linux server? These shell scripts pertain to some applications and must startup with a different user rather than root user. I was thinking of writing a script and have sysinit start it up during the reboot. However, I am not sure where to start. Please help. Thank you in advance. J |
Put the script at rc.local directory under /etc/init.d top directory.
that will make the script execute during the bootup. |
WHat you need to do is :
1.) make a file under /etc/rc.d/init.d - example " vi /etc/rc.d/init.d/filename " In this file write or copy the script 2.) chmod 755 /etc/rc.d/init.d/filename " This will make the file executable 3.) make a symbolic link to tell Linux to execute at startup cd /etc/rc.d/rc3.d " - if your runlevel in runlevel 3 4.) while in /etc/rc.d/rc3.d do - ln -s ../init.d/filename S55FILENAME that is it |
Quote:
Here's the command that I execute manually: nohup ./agentscheduler.sh -port=9003 -name=THRASHER1_9003 & nohup ./agent.sh -port=9004 -name=THRASHER1_9004 & When I run the command above, I had to logged in as 'a_agent' user account to execute it. if so, I do I incorporate that user in the script?? Thank you!! J |
I have a script in /etc called rc.local where I added a startup command for a test Forum.
The script original had one uncommented line "exit 0" and I added my command just above that. ----------------------- #!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. /opt/lampp/lampp start exit 0 ------------------------------------------- |
Quote:
|
Hi,
Change your startup script to add the following to the start of your commands: su a_agent Ian |
Quote:
|
Actually, no. root can su to a user without having to specify a passwd.
@xmdms; I'd use 'su -' to ensure the process has the newuser's env as well. Here's an example su - -c "/home/chris/t.sh" chris put that in /etc/rc.local (or the equiv.) Depends on your distro. Add distro to your profile. |
Quote:
I will try as your suggested. Thank you!! |
I was under the impression root was not allowed to run the script or execute it ... sorry
|
There's always something to learn in IT
;) That cmd runs it 'as the other user', but its 'called/originated from a root process' eg /etc/rc.local. |
Quote:
Do I put the command "exit 0" after each command line I execute or just once at the end of the script? Thanks, J |
Actually you don't need to use it at all.
The default exit status of a shell script is that (ie status) of the last cmd run. You only need to specify it explicitly if you have a wrapper script that checks the exit status. |
Got it!!
Thank you!! |
All times are GMT -5. The time now is 02:19 AM. |