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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
05-18-2012, 05:53 PM
|
#1
|
Member
Registered: Apr 2010
Posts: 82
Rep:
|
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 .
|
|
|
05-18-2012, 06:18 PM
|
#2
|
Senior Member
Registered: Jan 2012
Distribution: Slackware
Posts: 3,348
Rep:
|
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.
|
|
|
05-18-2012, 07:05 PM
|
#3
|
Member
Registered: Apr 2010
Posts: 82
Original Poster
Rep:
|
Quote:
Originally Posted by Ser Olmy
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
|
|
|
05-19-2012, 12:18 AM
|
#4
|
LQ Guru
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573
|
Quote:
Originally Posted by fachhoch@gmail.com
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.
|
|
|
05-19-2012, 02:16 AM
|
#5
|
Member
Registered: Mar 2012
Location: New Jersey
Distribution: Gentoo
Posts: 291
Rep:
|
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.
|
|
|
05-19-2012, 06:26 PM
|
#6
|
LQ Guru
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,326
|
one option is adding it to your .bash_profile. another option would be adding an @reboot line to your crontab.
|
|
|
05-19-2012, 09:15 PM
|
#7
|
Senior Member
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290
|
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).
|
|
|
05-19-2012, 11:10 PM
|
#8
|
Member
Registered: Jun 2007
Distribution: Debian, SLES, Ubuntu
Posts: 308
Rep:
|
You can add it to cron with @boot as the option.
|
|
|
05-19-2012, 11:42 PM
|
#9
|
Member
Registered: Mar 2012
Location: New Jersey
Distribution: Gentoo
Posts: 291
Rep:
|
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.
|
|
|
05-20-2012, 12:19 AM
|
#10
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
|
Quote:
Originally Posted by amboxer21
Daemonize with the -dmS switch.
|
Which shell are the d, m and S options for?
|
|
|
05-20-2012, 12:25 AM
|
#11
|
Member
Registered: Mar 2012
Location: New Jersey
Distribution: Gentoo
Posts: 291
Rep:
|
@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.
|
|
|
05-20-2012, 12:31 AM
|
#12
|
Member
Registered: Mar 2012
Location: New Jersey
Distribution: Gentoo
Posts: 291
Rep:
|
unnecessary post.
Last edited by amboxer21; 05-20-2012 at 12:39 AM.
|
|
|
05-20-2012, 12:55 AM
|
#13
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
|
Quote:
Originally Posted by amboxer21
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 '
|
|
|
05-20-2012, 01:09 AM
|
#14
|
Member
Registered: Mar 2012
Location: New Jersey
Distribution: Gentoo
Posts: 291
Rep:
|
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.
|
|
|
05-20-2012, 01:53 AM
|
#15
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
|
Quote:
Originally Posted by amboxer21
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
|
|
|
All times are GMT -5. The time now is 04:53 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|