Created
December 6, 2016 16:53
-
-
Save pboothe/34ba3b90474c3c3991a199248a48d3ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
has_it_been_24_hrs() { | |
echo "#### Starting has_it_been_24_hrs ####" | |
echo "Contents of REBOOT_CANDIDATES (/tmp/rebot-testing/ssh_outage/reboot_candidates:" | |
cat ${REBOOT_CANDIDATES} | |
echo "Contents of REBOOT_LOG (/tmp/rebot-testing/reboot_history/reboot_log:" | |
cat ${REBOOT_LOG} | |
#echo "# Starting timestamp comparison #" | |
echo "" | |
rm -f "${REBOOT_CANDIDATES}.tmp" && touch "${REBOOT_CANDIDATES}.tmp" | |
for host in `cat "${REBOOT_CANDIDATES}"`; do | |
if grep -q $host "${REBOOT_LOG}" ; then | |
echo "" | |
#echo "$host found in REBOOT_LOG. Checking its timestamp to see if it's been more than 24 hours." | |
PREVIOUS_REBOOT=`grep $host $REBOOT_LOG | head -1 | awk -F: '{print $3 }'` | |
#echo "Previous reboot:" $PREVIOUS_REBOOT | |
SECONDS_SINCE_REBOOT=$(($EPOCH_NOW - $PREVIOUS_REBOOT )) | |
#echo "$host previous reboot:" $PREVIOUS_REBOOT". Seconds since: "$SECONDS_SINCE_REBOOT". Should be more than 86400." | |
if [ "${SECONDS_SINCE_REBOOT}" -gt 86400 ]; then | |
echo $host >> "${REBOOT_CANDIDATES}.tmp" | |
# echo "More than a day since $host was rebooted. Ok to reboot." | |
else | |
# echo "Less than a day since $host was rebooted. Not ok to reboot." | |
echo "Less than a day since $host was rebooted (${SECONDS_SINCE_REBOOT}" \ | |
"seconds. Should be more than 86400.) Not ok to reboot." > ${NOTIFICATION_EMAIL} | |
fi | |
else | |
echo $host >> "${REBOOT_CANDIDATES}.tmp" | |
# echo "$host is not present in the REBOOT_LOG. Ok to proceed." | |
fi | |
done | |
mv "${REBOOT_CANDIDATES}.tmp" "${REBOOT_CANDIDATES}" | |
# echo "" | |
# echo "New Contents of REBOOT_CANDIDATES (/tmp/rebot-testing/ssh_outage/reboot_candidates:" | |
# cat ${REBOOT_CANDIDATES} | |
# echo "" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment