Shell script - check uptime

 

Very primitive but very effective. I set mine to run once every five minutes, which means that after a reboot for the first hour I get spammed with alerts that the box has been rebooted. You might want to adjust it to check maybe once every 15 minutes.

 
 

#!/bin/bash
#
# Check uptime and mail if uptime is less than 1 hour. 
#

UPTIME=`gawk -F . '{ print $1 }' /proc/uptime`

MINS=$(($UPTIME/60))
HOURS=$(($MINS/60))
DAYS=$(($HOURS/24))

# Unhash below line for testing.
#HOURS='0'

if [ "$HOURS" -lt '1' ] ;
then
    uptime | mail -s "`hostname` has been rebooted" email@uplinkzero.nospam.com ;
fi