donde321
Posts: 11
Joined: Mon Apr 11, 2016 10:54 pm

Run script on start up

Mon Apr 11, 2016 11:11 pm

I am now using a Pi Zero with latest March 2016 Jessie.
It seems impossible to come up with a startup script. I've tried cron with @boot,
rc.local, bashrc, init.d and all kinds of variations. Nothing seems to work right. Does jessie have a different way to start a script automatically. I have been on Google with key words of Raspberry Pi and start script on boot up. I've seen 10's of ways to do this. Some work, many don't. Some one please help

DirkS
Posts: 10371
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Run script on start up

Tue Apr 12, 2016 8:38 am

I've tried cron with @boot,
That should be @reboot

But the best / correct method depends on the script you want to run.
Does it have any screen output (text / graphical) or not?
Does it expect user input?
etc.
So you should describe first what your script does and if / how it interacts with the user.

And please elaborate on what you mean by 'Nothing seems to work right': does your script start at all?
Or does it start, but it doesn't work as expected.

texy
Forum Moderator
Forum Moderator
Posts: 5161
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: Run script on start up

Tue Apr 12, 2016 9:30 am

Hi,
cron is working fine with my Jessie install, so for me using

Code: Select all

sudo crontab -e
shows my entry :

Code: Select all

# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command
@reboot /usr/bin/python /home/pi/thermo.py
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

donde321
Posts: 11
Joined: Mon Apr 11, 2016 10:54 pm

Re: Run script on start up

Tue Apr 12, 2016 2:45 pm

Nothing seems to work right
I agree, not a definitive statement!
Here is what I want to do. Run a startup script for this before or after main RPi boot.
http://frederickvandenbosch.be/?p=1365
I tried the author's method here, no success.
]He says:
Finally, to get it to start automatically at boot time, create a launcher script (e.g. “launcher.sh”) containing the path to the script, like so:

Code: Select all

#!/bin/sh
cd /home/pi
sudo python info_display.py &
And lastly, add the cronjob using the “sudo crontab -e” command:
@reboot sh /home/pi/launcher.sh
Every time the Pi is booted, the script will be launched.

Have been trying to use the new systemd methods, but a bit lost.
Don't need monitor, just the project to start after power is applied.

texy
Forum Moderator
Forum Moderator
Posts: 5161
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: Run script on start up

Tue Apr 12, 2016 2:53 pm

Make sure the launcher.sh file is executable :

Code: Select all

sudo chmod +x launcher.sh
Double check with

Code: Select all

ls -lt launcher.sh
You may also need to change to

Code: Select all

sudo /usr/bin/python /home/pi/info_display.py &
Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

donde321
Posts: 11
Joined: Mon Apr 11, 2016 10:54 pm

Re: Run script on start up

Tue Apr 12, 2016 3:13 pm

Thanks Texy, I'll try again. I know I can get it to work with wheezy, but jessie is a whole different animal. Almost all methods that worked before, like rc.local,
or @reboot don't now. Just from the many blogs I'm reading. Very confusing.

User avatar
RaTTuS
Posts: 10563
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Run script on start up

Tue Apr 12, 2016 3:29 pm

donde321 wrote:Thanks Texy, I'll try again. I know I can get it to work with wheezy, but jessie is a whole different animal. Almost all methods that worked before, like rc.local,
or @reboot don't now. Just from the many blogs I'm reading. Very confusing.
poppycock and balderdash
they all work just as before
the only things that may be troublesome are things that expect things to be up before they are run ...
rc.local get run at a much earlier start in the system
but if your scripts are good then things should be fine
YMMV but not by much
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

donde321
Posts: 11
Joined: Mon Apr 11, 2016 10:54 pm

Re: Run script on start up

Tue Apr 12, 2016 5:22 pm

poppycock and balderdash
they all work just as before
So, I should use what the author shows to start and add a 10 second delay?

User avatar
RaTTuS
Posts: 10563
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Run script on start up

Wed Apr 13, 2016 6:39 am

post your script and
what does it do
what is it supposed to do
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

donde321
Posts: 11
Joined: Mon Apr 11, 2016 10:54 pm

Re: Run script on start up

Wed Apr 13, 2016 11:17 pm

post your script and
what does it do
what is it supposed to do
Figured it out. Went to here to set up rc.local using systemd.

https://www.linuxbabe.com/linux-server/ ... th-systemd

All is well. Try it, you'll like it.

Return to “Troubleshooting”