How do I start up a shell script when the system starts?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
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.
The easiest way is to stick the script in /etc/rc.d/rc.local. Other that that, you put your script in /etc/rc.d/init.d and make the appropriate links to the runlevels you want the script to run in by liniking the script to the appropriate /etc/rc.d/rc*.d directory.
There are a number of places where that can be done. The right place to do it depends a lot on what the script is supposed to accomplish. If you could clarify that it would make it easier to give a good answer.
If what you want to do is something along the lines of starting up a service process then putting a properly structured script in /etc/init.d and setting up the appropriate links to it with chkconfig could be an option. Then you could specify which run levels you want the script to be executed for.
Another option is running it from /etc/rc.d/rc.local which is intended for system customization and runs after the /etc/init.d scripts. This may be important if your script is going to depend on something that the system startup scripts have launched.
Also, I assume you want it to start during boot up. If you wanted it to start on login that would be done differently.
For a GUI desktop, fedora normally boots to runlevel 5. For a text login like you typically have on a server, fedora boots to runlevel 3. As noted above, we need more details about what exactly you want to accomplish. Scripts launched from rc.local or init.d run with root privileges which may not be what you want.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.