0

I have a script that runs in the foreground and sometimes that script stuck in the process (not closing) just not working because of the system failure (like the drive is not accessible).

I want whenever this happened; it kills the process without exiting the script and rerun it.

So far I know how to get the PID for the specific script (with the command $$), and I can kill the script with ( kill -9 $$ ), but that cause the script get close, and I want it to stay open.

This is my script; any help would be appreciated.

Also I'm running this script in Mac Terminal.

n=1 ;

while true ; do

acd_cli -d -nl mount -fg /Users/Danial/amazon && 

if [ `find /Users/Danial/amazon -prune -empty` ] ; then
    sleep 30
fi ;

if [ `find /Users/Danial/amazon -prune -empty` ] ; then
    echo "=============================================="
    echo "System were down  $(date)"
    echo "=============================================="
    acd_cli umount /Users/Danial/amazon
else
    echo "=============================================="
    echo "System were ok at $(date)"
    echo "=============================================="
fi ;

n=$((n+1)) ;

done
  • you can probably run a checker script that checks the status of your first script. – Jay T. Feb 24 '16 at 21:59
  • Do you mind explain this more ? – Danial M.Hassan Feb 24 '16 at 22:00
  • sure, here are some links that might help you: 1) http://superuser.com/questions/507576/how-to-automatically-restart-a-linux-background-process-if-it-fails 2) http://serverfault.com/questions/45593/how-do-i-automatically-restart-a-process-on-server-reboot-process-exit 3) http://www.perlmonks.org/?node_id=603978 4) http://stackoverflow.com/questions/696839/how-do-i-write-a-bash-script-to-restart-a-process-if-it-dies – Jay T. Feb 24 '16 at 22:03
  • Thanks :) I will check them . – Danial M.Hassan Feb 24 '16 at 22:10

0 Answers0