LinuxQuestions.org
Visit Jeremy's Blog.
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 09-25-2008, 08:01 AM   #1
xmdms
Member
 
Registered: Oct 2003
Posts: 134

Rep: Reputation: 15
Question 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
 
Old 09-25-2008, 08:14 AM   #2
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,461
Blog Entries: 6

Rep: Reputation: 51
Put the script at rc.local directory under /etc/init.d top directory.
that will make the script execute during the bootup.
 
Old 09-25-2008, 08:18 AM   #3
linuxgurusa
Member
 
Registered: Mar 2008
Location: Namibia, Swakopmund
Distribution: Redhat, Fedora, Centos, ClearOS, Mandrake
Posts: 150

Rep: Reputation: 27
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
 
Old 09-25-2008, 08:56 AM   #4
xmdms
Member
 
Registered: Oct 2003
Posts: 134

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by linuxgurusa View Post
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
 
Old 09-25-2008, 09:04 AM   #5
john test
Member
 
Registered: Jul 2008
Distribution: ubuntu 9.10
Posts: 527
Blog Entries: 1

Rep: Reputation: 35
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
-------------------------------------------
 
Old 09-25-2008, 09:09 AM   #6
linuxgurusa
Member
 
Registered: Mar 2008
Location: Namibia, Swakopmund
Distribution: Redhat, Fedora, Centos, ClearOS, Mandrake
Posts: 150

Rep: Reputation: 27
Quote:
Originally Posted by xmdms View Post
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 )
 
Old 09-25-2008, 09:23 AM   #7
IW2B
Member
 
Registered: Aug 2008
Location: Denmark
Distribution: Fedora, Ubuntu, Solaris
Posts: 35

Rep: Reputation: 19
Hi,

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

su a_agent

Ian
 
Old 09-25-2008, 09:26 AM   #8
linuxgurusa
Member
 
Registered: Mar 2008
Location: Namibia, Swakopmund
Distribution: Redhat, Fedora, Centos, ClearOS, Mandrake
Posts: 150

Rep: Reputation: 27
Quote:
Originally Posted by IW2B View Post
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 ?
 
Old 09-25-2008, 09:31 PM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,247

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
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.
 
Old 09-25-2008, 10:48 PM   #10
xmdms
Member
 
Registered: Oct 2003
Posts: 134

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by chrism01 View Post
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!!
 
Old 09-26-2008, 12:58 AM   #11
linuxgurusa
Member
 
Registered: Mar 2008
Location: Namibia, Swakopmund
Distribution: Redhat, Fedora, Centos, ClearOS, Mandrake
Posts: 150

Rep: Reputation: 27
I was under the impression root was not allowed to run the script or execute it ... sorry
 
Old 09-26-2008, 01:38 AM   #12
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,247

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
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.
 
Old 10-03-2008, 08:23 AM   #13
xmdms
Member
 
Registered: Oct 2003
Posts: 134

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by xmdms View Post
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
 
Old 10-05-2008, 09:56 PM   #14
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,247

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
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.
 
Old 10-05-2008, 11:41 PM   #15
xmdms
Member
 
Registered: Oct 2003
Posts: 134

Original Poster
Rep: Reputation: 15
Got it!!

Thank you!!
 
  


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
shell script to automate TELNET daggulasreedhar Programming 5 08-02-2007 01:13 PM
How to program shell script to automate mass user account creation? EsAsher Linux - General 2 06-30-2007 09:41 AM
Automate FTP session using Shell Script kalyanofb Programming 2 04-07-2007 09:44 AM
startup script when reboot ust Linux - Software 5 09-10-2005 07:19 PM


All times are GMT -5. The time now is 05:42 PM.

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