Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 12-10-2009, 06:28 AM   #1
LQ Newbie
Registered: Nov 2009
Posts: 10

Rep: Reputation: 0
start script bash when system start,stop,reeboot, how ??

Hi, I have 3 script BASH.

I want start this script when the system start,stop and reeboot.

Can I do it??


Thanks a lot!
Old 12-10-2009, 06:40 AM   #2
LQ Guru
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Make a script called foo that takes the arguments start, stop and restart. Put it in the directory /etc/init.d/

Here I'm assuming that your default runlevel is 2 (Debian and I guess Ubuntu default), so make a link:
ln -s /etc/init.d/foo /etc/rc2.d/S99foo
At boot time this script will be called with the "start" argument, at shutdown with the "stop" argument. Have a look at the other scripts in /etc/init.d/ and google for inspiration.



Last edited by evo2; 12-10-2009 at 06:40 AM. Reason: Typo
Old 12-10-2009, 06:41 AM   #3
Senior Member
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
This link might be worth reading.
Old 12-10-2009, 06:53 AM   #4
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
The boot script system varies from distro to distro. In a system using /etc/init.d/ and /etc/rc[0-6S].d/ directories it is the K* symlinks that are run with the "stop" argument during shutdown. Which distro are you using?
Old 12-10-2009, 06:58 AM   #5
LQ Newbie
Registered: Nov 2009
Posts: 10

Original Poster
Rep: Reputation: 0
Originally Posted by catkin View Post
Which distro are you using?
I use Ubuntu 9.10


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 On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script start gedit but don't stop there Watchin Linux - General 7 10-30-2009 12:39 AM
make a bash script start automaticly when system restart sezam2 Programming 1 04-04-2009 08:27 PM
AWK- processing data inside start/stop pairs but ignoring start/stop lines cliffoij Programming 2 10-15-2008 06:17 AM
Start and stop a bash script based on network activity? creativetweak Linux - Software 8 05-04-2008 10:28 PM
using cron to start and stop a bash script monty Linux - Software 2 03-20-2006 02:30 PM

All times are GMT -5. The time now is 09:27 AM.

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