0

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.

Alex01
  • 330
  • 3
  • 14
  • 1
    This might help: [How do I write a bash script to restart a process if it dies?](http://stackoverflow.com/q/696839/3776858) or [Script to check for process & restart program if not found](http://stackoverflow.com/q/18790421/3776858) – Cyrus May 28 '16 at 18:12
  • 1
    Cyrus, thank you I've found my answer here [Script to check for process & restart program if not found](http://stackoverflow.com/questions/18790421/script-to-check-for-process-restart-program-if-not-found) – Alex01 May 28 '16 at 18:41

0 Answers0