#!/usr/bin/env bash if [ -z ${1} ] || [ -z ${2} ]; then echo "USAGE: ${0} " 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