I am trying to run a simple .sh script on reboot. I would like to have this script running forever. I have this script in a folder in the user directory, in /home/user/folder/script.sh
. It runs on a simple vps, and I have access through ssh. If I run it by doing ./script.sh &
while I am in the same directory, it works perfectly. When I close the ssh connection, it stops.
I tried to add a crontab entry like this one: @reboot /home/user/folder/script.sh &
(as suggested in other answers) and then just type sudo reboot
but it doesn't work.
I don't know which one is the best solution to this problem. The script.sh is this one (I found it while searching for some solution to restart the python start.py if it crashes):
until ./start.py; do
echo "Server 'myserver' crashed with exit code $?. Respawning.." >&2
sleep 1
done
And it does exactly what I need.
Thank you for your help!