Add it to cron.
sudo crontab -e
@reboot /path/to/script.sh
How to start a *.sh file at bootup?
Moderator: leecollings
-
ben53252642
- Posts: 543
- Joined: Saturday 02 July 2016 5:17
- Target OS: Linux
- Domoticz version: Beta
- Contact:
Re: How to start a *.sh file at bootup?
An alternative method is to make an init.d script that runs your script on startup:
nano /etc/init.d/NAMEOFSCRIPT
Then run these commands:
chmod 755 NAMEOFSCRIPT
update-rc.d NAMEOFSCRIPT defaults
Make sure the command you want the script to run works from the terminal:
eg: sudo /root/scripts/myscript.sh
Some systems might not need the sudo, otherwise to install it: apt-get install sudo
nano /etc/init.d/NAMEOFSCRIPT
Code: Select all
#!/bin/sh
### BEGIN INIT INFO
# Provides: startscripts
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 2 3 5
# Default-Stop:
# Description: Starts the script
### END INIT INFO
case "$1" in
'start')
sudo /root/scripts/myscript.sh
;;
'stop')
;;
*)
echo "Usage: $0 { start | stop }"
;;
esac
exit 0
chmod 755 NAMEOFSCRIPT
update-rc.d NAMEOFSCRIPT defaults
Make sure the command you want the script to run works from the terminal:
eg: sudo /root/scripts/myscript.sh
Some systems might not need the sudo, otherwise to install it: apt-get install sudo
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: How to start a *.sh file at bootup?
Continuing on this init.d script:
Do you know how to run a script at shutdown and reboot?
I need to run a script before domoticz and apache are stopped. Already tried with a init.d script but no luck so far.
Do you know how to run a script at shutdown and reboot?
I need to run a script before domoticz and apache are stopped. Already tried with a init.d script but no luck so far.
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: How to start a *.sh file at bootup?
the script is executable? Also for the root user?
Did you try with chmod 755?
Did you try with chmod 755?
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: How to start a *.sh file at bootup?
what is the output of the command sudo crontab -l ?
Could be that cron is already starting your script before all dependencies are fulfilled. A quick (and dirty) work-around for that is to
change the line into:
Could be that cron is already starting your script before all dependencies are fulfilled. A quick (and dirty) work-around for that is to
change the line into:
Code: Select all
@reboot sleep 60 && /home/pi/domoticz/nefitserver.sh
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: How to start a *.sh file at bootup?
what is the output of the command sudo crontab -l ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Who is online
Users browsing this forum: No registered users and 1 guest