Cubuss
Posts: 9
Joined: Sat Sep 14, 2019 3:15 pm

[How can i run a bash script on boot with Pi 4B /4GB]

Sun Sep 15, 2019 2:46 am

i need to run a simple .sh script on boot that requires internet,
But it doesnt start when i reboot or boot the pi, i already tried using crontab

Code: Select all

@reboot script.sh
also tried messing around with rc.local with no luck,

Any suggestion or help is appriciated

User avatar
Gavinmc42
Posts: 3758
Joined: Wed Aug 28, 2013 3:31 am

Re: [How can i run a bash script on boot with Pi 4B /4GB]

Sun Sep 15, 2019 4:49 am

My scripts wait until there is a valid IP address.
Then they send me an email so I know what it is.
It can take some time before the server on a network assigns it.
30 secs after booting is not unusual.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

jbudd
Posts: 996
Joined: Mon Dec 16, 2013 10:23 am

Re: [How can i run a bash script on boot with Pi 4B /4GB]

Sun Sep 15, 2019 7:23 am

You shouldn't assume that cron knows where to find your script. It's best to use the full pathname.
If you redirect the script output to a logfile you may get a clue to what went wrong.

Try @reboot /home/pi/script.sh >/home/pi/script.log 2>&1 (or wherever script.sh is).

You could put sleep 10 in the script to see if that gives time for a connection

User avatar
graysky
Posts: 92
Joined: Fri Apr 05, 2013 11:43 am
Location: /run/user/1000
Contact: Website

Re: [How can i run a bash script on boot with Pi 4B /4GB]

Sun Sep 15, 2019 8:12 am

You could write systemd service to execute it for you once the network is up rather than a sleep line... I assume your distro is using systemd.

For an example, see: https://github.com/graysky2/odroid-auto ... ge.service

Return to “Beginners”