As the user (don’t need to be root).
# one time setup: echo "down" > xenstatus.txt
checkXenSsh.sh:
#!/bin/bash
# one time setup: echo "down" > xenstatus.txt
STATUSFILE=/home/pi/xenstatus.txt
LASTSTATUS=$(cat "$STATUSFILE")
# check connection
ssh -q root@xen.florida exit
# status of ssh is stored in $?
if [ `echo $?` = 255 ]; then
nohup /opt/settings/scripts/speak.sh "zen server is down" >/dev/null 2>&1 &
echo "down" > $STATUSFILE
else
if [ "$LASTSTATUS" = "down" ]; then
nohup /opt/settings/scripts/speak.sh "zen server is now back up and running" >/dev/null 2>&1 &
echo "up" > $STATUSFILE
fi
fi
Make it executable:
chmod u+x checkXenSsh.sh
crontab -e
* * * * * /home/pi/checkXenSsh.sh
Also see speak.sh when mount point is down.