Page 1 of 1
Re: How to start a *.sh file at bootup?
Posted: Thursday 11 January 2018 6:19
by Egregius
Add it to cron.
sudo crontab -e
@reboot /path/to/script.sh
Re: How to start a *.sh file at bootup?
Posted: Thursday 11 January 2018 15:08
by jannl
Correct
Re: How to start a *.sh file at bootup?
Posted: Thursday 11 January 2018 15:32
by ben53252642
An alternative method is to make an init.d script that runs your script on startup:
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
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
Re: How to start a *.sh file at bootup?
Posted: Thursday 11 January 2018 15:45
by Egregius
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.
Re: How to start a *.sh file at bootup?
Posted: Thursday 11 January 2018 16:11
by Egregius
the script is executable? Also for the root user?
Did you try with chmod 755?
Re: How to start a *.sh file at bootup?
Posted: Thursday 11 January 2018 16:29
by waaren
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:
Code: Select all
@reboot sleep 60 && /home/pi/domoticz/nefitserver.sh
Re: How to start a *.sh file at bootup?
Posted: Thursday 11 January 2018 16:46
by waaren
what is the output of the command sudo crontab -l ?