I'm running a program that from time to time stop working (Network issues).
I'm now using this bash shell script to re-start it if it is not already running.
Here are the contents:
#!/bin/bash # Use ps and grep to check if the program is running ps -ef | grep -v grep | grep offlineimap # grep -v grep, keeps grep command itself out of the question # if it is not running, start it. if [ $? -eq 1 ] then # Your code to start the program goes here # Could be something like: nohup rsync -av /some/folder /some/other/folder & else # What to do if it is already or still running echo "The program is still running." fi
I'm using nohup to detach the other program from this script.