aflfiuza
Posts: 6
Joined: Tue Feb 19, 2013 12:20 am

Script at startup

Fri Mar 08, 2013 11:30 pm

hello!
I have some python (.py) script's, and i need to run it at startup, how i can do it?
I need help, i can't run at startup

User avatar
Jim Manley
Posts: 1600
Joined: Thu Feb 23, 2012 8:41 pm
Location: SillyCon Valley, California, and Powell, Wyoming, USA, plus The Universe
Contact: Website

Re: Script at startup

Sat Mar 09, 2013 4:56 am

Create a file named something like /etc/init.d/startup_script and enter the following into the file:

#! /bin/sh
python /home/pi/my_python.py

The actual path to your Python file and the name of the file should be substituted for /home/pi/my_python.py in the above script.

Then, make startup_script executable:
sudo chmod +x /etc/init.d/startup_script

Finally, you need to register startup_script so that it will run during startup:
sudo update-rc.d startup_script defaults

Now, restart your Pi and enjoy your Python script doing its thing.
The best things in life aren't things ... but, a Pi comes pretty darned close! :D
"Education is not the filling of a pail, but the lighting of a fire." -- W.B. Yeats
In theory, theory & practice are the same - in practice, they aren't!!!

User avatar
LetHopeItsSnowing
Posts: 357
Joined: Sat May 26, 2012 6:40 am
Location: UK
Contact: Website

Re: Script at startup

Sat Mar 09, 2013 9:14 am

If you want some instructions head over to http://www.stuffaboutcode.com/2012/06/r ... rt-up.html
"am I getting slower, or is stuff more complicated; either way I now have to write it down - stuffaboutcode.com"

aflfiuza
Posts: 6
Joined: Tue Feb 19, 2013 12:20 am

Re: Script at startup

Sun Mar 10, 2013 9:17 pm

Jim Manley wrote:Create a file named something like /etc/init.d/startup_script and enter the following into the file:

#! /bin/sh
python /home/pi/my_python.py

The actual path to your Python file and the name of the file should be substituted for /home/pi/my_python.py in the above script.

Then, make startup_script executable:
sudo chmod +x /etc/init.d/startup_script

Finally, you need to register startup_script so that it will run during startup:
sudo update-rc.d startup_script defaults

Now, restart your Pi and enjoy your Python script doing its thing.
Ok, i tryed, but when make sudo update +x /etc/init.d script_startup defaults i receive this message:
"update-rc.d: using dependency based boot sequencing
insserv: warming: script 'script_startup' missing LSB tag and overrides"
And when start rpi break at load system operative.
What is wrong?

JAMOV13
Posts: 2
Joined: Tue Feb 26, 2013 2:27 am
Location: New Zealand

Re: Script at startup

Thu Mar 14, 2013 1:16 am

I also have this problem.

User avatar
DetlevSchm
Posts: 72
Joined: Tue Mar 12, 2013 8:43 am
Location: 3rd planet

Re: Script at startup

Thu Mar 14, 2013 7:57 am

You did not state, whether you need the script to be run as part of the boot sequence (as descibed above by Jim), or after the GUI has been established. In the latter case, see the answer for "question 1" here: http://www.raspberrypi.org/phpBB3/viewtopic.php?t=18968. This is less complex to implement, if applicable.

As for the "LSB tags", google that and you will find a lot of complicated stuff :-).

User avatar
theoB610
Posts: 233
Joined: Sat Jan 05, 2013 12:40 pm
Location: Devon

Re: Script at startup

Thu Mar 14, 2013 9:44 am

Stick the code that you want to run in /etc/rc.local. I haven't tried it with a script, but I'm pretty sure it should work fine.

Heres a link:
http://askubuntu.com/questions/9853/how ... on-startup

Return to “General discussion”