[SOLVED] can i write a shell script in /etc/init.d that will run a python script?
DebianThis forum is for the discussion of Debian Linux.
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.
can i write a shell script in /etc/init.d that will run a python script?
What i want to do is write a script to put in the /etc/init.d folder that will run. a python script. I cannot figure out how i would put pyhon commands in the skeleton provided. If someone could write a script that would work, it would be much appreciated
The skeleton provide is a shell script but has key elements that need to be there understood by the startup routines. Your python script would not be.
However, you could simply tell the start, stop, status etc... sections of that skeleton to call your python script(s) (with the appropriate flags if any).
You can get the hplip init script online to find an example of one that contains calls to .py files. The Postgresql init script calls the pg_ctl binary so that would be an example of that. I don't have Debian but I suspect if you look through existing files you'll find where they are calling other things such as python, perl, binaries etc....
Note that /etc/init.d is just where the base script lives - you have to make sure you put links in the run level directories (e.g. /etc/rc2.d, /etc/rc3.d etc...).
Note that just like with cron jobs you have to make sure all environment variables you need are in the script itself or sourced by it as it will NOT automatically have the same environment variables it would inherit from a logged in shell session.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.