LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 05-18-2012, 05:53 PM   #1
fachhoch@gmail.com
Member
 
Registered: Apr 2010
Posts: 82

Rep: Reputation: 1
call my.sh at boot up


I have a simple .sh file ,I want linux to call this at boot up , please advice me how to .
 
Old 05-18-2012, 06:18 PM   #2
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 2,469

Rep: Reputation: Disabled
Call it from one of the system startup scripts.

I can't be more specific without knowing which distribution you're using, but calling it from rc.local (usually found in /etc, /etc/init.d or /etc/rc.d) is pretty much guaranteed to work.
 
Old 05-18-2012, 07:05 PM   #3
fachhoch@gmail.com
Member
 
Registered: Apr 2010
Posts: 82

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by Ser Olmy View Post
Call it from one of the system startup scripts.

I can't be more specific without knowing which distribution you're using, but calling it from rc.local (usually found in /etc, /etc/init.d or /etc/rc.d) is pretty much guaranteed to work.
here is my cat /proc/version

Code:
[ec2-user@domU-12-31-39-16-9D-E7 ~]$ cat /proc/version 
Linux version 3.2.12-3.2.4.amzn1.x86_64 (mockbuild@gobi-build-31003) (gcc version 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC) ) #1 SMP Thu Mar 22 08:00:08 UTC 2012
 
Old 05-19-2012, 12:18 AM   #4
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,552

Rep: Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112Reputation: 2112
Quote:
Originally Posted by fachhoch@gmail.com View Post
here is my cat /proc/version

Code:
[ec2-user@domU-12-31-39-16-9D-E7 ~]$ cat /proc/version 
Linux version 3.2.12-3.2.4.amzn1.x86_64 (mockbuild@gobi-build-31003) (gcc version 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC) ) #1 SMP Thu Mar 22 08:00:08 UTC 2012
I've never seen a Redhat-based release that didn't run /etc/rc.local on boot. That's not to say they don't exist, most of my experience is with Fedora, but there's no harm in trying.
 
Old 05-19-2012, 02:16 AM   #5
amboxer21
Member
 
Registered: Mar 2012
Location: New Jersey
Distribution: Gentoo
Posts: 291

Rep: Reputation: Disabled
For Ubuntu, or any variant of; Add the script to /etc/init.d/ give it the proper persmission and update rc.d with defaults for that script.

Lets say your script name is script.sh; copy the script to the /etc/init.d/ dir from the command line then chmod it. Then run, "update-rc.d script.sh defaults". It will then run on next boot.

Last edited by amboxer21; 05-19-2012 at 02:21 AM.
 
Old 05-19-2012, 06:26 PM   #6
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,150

Rep: Reputation: 887Reputation: 887Reputation: 887Reputation: 887Reputation: 887Reputation: 887Reputation: 887
one option is adding it to your .bash_profile. another option would be adding an @reboot line to your crontab.
 
Old 05-19-2012, 09:15 PM   #7
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,284

Rep: Reputation: 371Reputation: 371Reputation: 371Reputation: 371
Adding it to the .bash_profile will only run it when a user logs in, whereas the OP wants it run at every boot. I think that the crontab option would work, but I think simply adding it to rc.local would be simpler (personal preference, though).
 
Old 05-19-2012, 11:10 PM   #8
grim76
Member
 
Registered: Jun 2007
Distribution: Debian, SLES, Ubuntu
Posts: 308

Rep: Reputation: 50
You can add it to cron with @boot as the option.
 
Old 05-19-2012, 11:42 PM   #9
amboxer21
Member
 
Registered: Mar 2012
Location: New Jersey
Distribution: Gentoo
Posts: 291

Rep: Reputation: Disabled
IMO, adding the script to rc.local/rc.d is much simpler than tinkering with crontab. In some cases the daemon is not enabled by default. With crontab, the trival task of making a script run on boot, then becomes a hassle for beginners. I prefer updating rc.d to crontab.

Sure, crontab is great for running scripts every n minutes but you could achieve the same with the watch command. Watch allows you to specify the job frequency in seconds. Unlike cron, which only allows minutes.

I say stick with adding the script to rc.local/rc.d! Daemonize with the screen command and the -dmS switches.

Last edited by amboxer21; 05-20-2012 at 12:44 AM.
 
Old 05-20-2012, 12:19 AM   #10
catkin
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
Quote:
Originally Posted by amboxer21 View Post
Daemonize with the -dmS switch.
Which shell are the d, m and S options for?
 
Old 05-20-2012, 12:25 AM   #11
amboxer21
Member
 
Registered: Mar 2012
Location: New Jersey
Distribution: Gentoo
Posts: 291

Rep: Reputation: Disabled
@Catkin, the dmS switches are used with Bash. I'm sorry, i did not specify that the -dms switches are used with the screen command and not the watch command.

Example:
Code:
screen -dmS name watch -n 60 /path/to/script.sh
above code runs as a daemon every 60 seconds from boot. screen detaches the proc, and watch runs the proc every n seconds.

chmod
drop script into /etc/init.d/ directory
run-> update-rc.d scriptname.sh defaults
reboot

Last edited by amboxer21; 05-20-2012 at 12:45 AM.
 
Old 05-20-2012, 12:31 AM   #12
amboxer21
Member
 
Registered: Mar 2012
Location: New Jersey
Distribution: Gentoo
Posts: 291

Rep: Reputation: Disabled
unnecessary post.

Last edited by amboxer21; 05-20-2012 at 12:39 AM.
 
Old 05-20-2012, 12:55 AM   #13
catkin
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
Quote:
Originally Posted by amboxer21 View Post
chmod
drop script into /etc/init.d/ directory
run-> update-rc.d scriptname.sh defaults
reboot
That does not work on all distros (and the chmod is missing some arguments).

If the .sh file is run from the boot scripts such as rc.local, the boot process will not continue until the .sh file finishes running. If this matters, the .sh file can be run in the background and the boot scripts allowed to continue by putting & after the file's name to "background" it.

Last edited by catkin; 05-20-2012 at 12:55 AM. Reason: Missing '
 
Old 05-20-2012, 01:09 AM   #14
amboxer21
Member
 
Registered: Mar 2012
Location: New Jersey
Distribution: Gentoo
Posts: 291

Rep: Reputation: Disabled
I know the chmod is missing arguments lol Specifically chmod u+x scriptname.sh and I didn't say it works on all distros either. I have only tested it on Ubuntu versions 10.10 - 12.04.

Last edited by amboxer21; 05-20-2012 at 01:10 AM.
 
Old 05-20-2012, 01:53 AM   #15
catkin
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
Quote:
Originally Posted by amboxer21 View Post
I know the chmod is missing arguments lol Specifically chmod u+x scriptname.sh and I didn't say it works on all distros either. I have only tested it on Ubuntu versions 10.10 - 12.04.
OK.

We don't know which distro fachhoch@gmail.com is using or their familiarity with the chmod command. Advice that may not work is confusing for beginners.

Last edited by catkin; 05-20-2012 at 01:53 AM. Reason: Removed hyperlink from fachhoch@gmail.com
 
  


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
how did a system call invoke kernel call,ie: fwrite->sys_write jinxin16897123 Linux - Kernel 1 04-05-2012 03:04 PM
call manager linux boot problem elie Linux - Server 6 08-12-2011 04:05 PM
How can i make centos 4.5's system call using vDSO(call *%gs:0x10) instead of int80 tclwp Red Hat 3 08-06-2007 01:07 AM
How can I script an autologin, automatically call kde(or simillar) and call an app aboaventura Slackware 8 02-04-2007 12:00 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:15 AM.

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