Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I would like to run the python script, when I startup the Linux machine. How can I do so? I don't need the user to login the OS to start the script. (The user is password protected.)

share|improve this question
3  
What distribution? Are you using upstart, systemd, or something else? –  David Schwartz Aug 23 '12 at 12:42
1  
Have you done much research into this? The top results when Googling your question comes up with links that say the exact same thing as the below answer from mnmnc. –  bobmagoo Aug 23 '12 at 12:58
    
possible duplicate of How do I make a script run upon startup of the Ubuntu machine? –  Indrek Aug 23 '12 at 17:46
    
@Indrek: It's not an exact duplicate, since this post does not specify Ubuntu, while the question is somewhat distro-specific. –  grawity Aug 23 '12 at 18:50

1 Answer 1

Generic method – add the script to /etc/rc.local:

/usr/bin/python pythonscript.py

if your python interpreter is under /usr/bin, or simply

/path/to/pythonscript.py

if your script is marked executable (+x).

Note that some systems use /etc/rc.d/rc.local instead.


On systemd systems, rc.local might be ignored completely.

Create a service unit, /etc/systemd/system/something.service:

[Unit]
Description=Script name

[Service]
ExecStart=/path/to/script.py

[Install]
WantedBy=multi-user.target

Tell systemd to start the script on boot with systemctl enable something.service.

share|improve this answer
2  
Although Ted explicitly asks about OS startup and not about user login, the proper place for post-login scripts is .profile, .xprofile and/or .config/autostart/. Adding something to .bashrc will cause it to be run every time a terminal is opened. –  grawity Aug 23 '12 at 17:15
    
i stand corrected. Thank you. –  mnmnc Aug 23 '12 at 17:19
2  
Just to note: on some systems, the file may be located at /etc/rc.d/rc.local. –  clpo13 Aug 23 '12 at 17:44
1  
@clpo13: And some systems might not be using rc.local at all (such as most systemd-using Linux distros)... –  grawity Aug 23 '12 at 17:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.