I have a loader.sh script which must be always running on the server.
The problem is that sometimes the server reboot.
I launch this loader.sh script manually with screen in order to be able to log out from the console and keep it running.
How can I check if this script (loader.sh) is running (with a cron every 5 minutes for example) then do nothing, if this script is not running then run it, like in the screen console.
I have done this restart.sh script (which will work with a cron) but I am really not sure of what I am doing exactly.
For example if I press ctrl+z after starting ./loader.sh the script restart.sh will not detect it as "not running".
There is what I have done with restart.sh following this tutorial
#!/bin/sh
ps auxw | grep loader.sh | grep -v grep > /dev/null
if [ $? != 0 ]
then
/path/to/script/loader.sh start > /dev/null
fi
Thank you for your help.