LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How would I automate shell script startup during a reboot?? (https://www.linuxquestions.org/questions/linux-newbie-8/how-would-i-automate-shell-script-startup-during-a-reboot-672277/)

xmdms 09-25-2008 07:01 AM

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

your_shadow03 09-25-2008 07:14 AM

Put the script at rc.local directory under /etc/init.d top directory.
that will make the script execute during the bootup.

linuxgurusa 09-25-2008 07:18 AM

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

xmdms 09-25-2008 07:56 AM

Quote:

Originally Posted by linuxgurusa (Post 3291272)
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

Thank you for the quick respoonse!! I need do something like 'su -u user_name' to execute the the script?? I wouldn't want root to execute this script due to security reason.

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

john test 09-25-2008 08:04 AM

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
-------------------------------------------

linuxgurusa 09-25-2008 08:09 AM

Quote:

Originally Posted by xmdms (Post 3291307)
Thank you for the quick respoonse!! I need do something like 'su -u user_name' to execute the the script?? I wouldn't want root to execute this script due to security reason.

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

Lol, good question ... I guess you would need to add an authentication section to do that, but would not be great to do , because you will have to store the password in the file ( which is clear text )

IW2B 09-25-2008 08:23 AM

Hi,

Change your startup script to add the following to the start of your commands:

su a_agent

Ian

linuxgurusa 09-25-2008 08:26 AM

Quote:

Originally Posted by IW2B (Post 3291335)
Hi,

Change your startup script to add the following to the start of your commands:

su a_agent

Ian

How would you authenticate that user then, it will expect a password ?

chrism01 09-25-2008 08:31 PM

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.

xmdms 09-25-2008 09:48 PM

Quote:

Originally Posted by chrism01 (Post 3291952)
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.


I will try as your suggested. Thank you!!

linuxgurusa 09-25-2008 11:58 PM

I was under the impression root was not allowed to run the script or execute it ... sorry

chrism01 09-26-2008 12:38 AM

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.

xmdms 10-03-2008 07:23 AM

Quote:

Originally Posted by xmdms (Post 3291307)
Thank you for the quick respoonse!! I need do something like 'su -u user_name' to execute the the script?? I wouldn't want root to execute this script due to security reason.

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

Hi Guys,

Do I put the command "exit 0" after each command line I execute or just once at the end of the script?

Thanks,

J

chrism01 10-05-2008 08:56 PM

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.

xmdms 10-05-2008 10:41 PM

Got it!!

Thank you!!


All times are GMT -5. The time now is 02:19 AM.