Skip to content

Instantly share code, notes, and snippets.

@danielhauck
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielhauck/d0053e113d2d73568807 to your computer and use it in GitHub Desktop.
Save danielhauck/d0053e113d2d73568807 to your computer and use it in GitHub Desktop.
Check your failover from time to time
#!/usr/bin/env bash
if [ -z ${1} ] || [ -z ${2} ]; then
echo "USAGE: ${0} <IP-TO-MONITOR> <PIVOT-DAYS>"
exit 1
fi
PIVOTDAYS=35 # how often should the failover be checked?(in days)
IP_TO_MONITOR=${1}
FAILOVER_IP=$(ip addr sh | grep -v "127.0.0.1" | grep "inet " | cut -d/ -f1 | awk '{print $2}' | grep -Fx ${IP_TO_MONITOR})
if [ -z "${FAILOVER_IP}" ];then
echo "[OK] Host is in Backup mode"
exit 0
fi
HASHFILE="/tmp/$(echo "${IP_TO_MONITOR}" | md5sum | cut -f1 -d' ')"
touch ${HASHFILE}
if test $(find ${HASHFILE} -ctime +${PIVOTDAYS})
then
echo "[CRIT] it is time to check the failover!"
exit 2
else
echo "[OK] still got some time"
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment