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