A simple ISP check script (bash)

Hi,

I recently wanted to log internet outages (ISP) so I wrote this script. The script it self has no license – so call it a free to modify, publish and use. I did set the script to run every five minutes via cron.

The code:

#!/bin/bash

current_date_time="`date "+%Y-%m-%d %H:%M:%S"`";

curl --head http://www.google.com > /dev/null 2>&1
OUT=$?

last_msg_start=""

if [ -e /var/log/ISP_Log ]
then
    last_msg_start="`sed -n '$,$ p' /var/log/ISP_Log | cut -c1-16`"
fi

if [ $OUT -eq 0 ]
then
    if [ "$last_msg_start" != "CONNECTION:[YES]" ]
    then
      echo "CONNECTION:[YES] $current_date_time" >> /var/log/ISP_Log
    fi
else
    if [ "$last_msg_start" == "CONNECTION:[YES]" ]
    then
      echo "CONNECTION:[N/A] $current_date_time" >> /var/log/ISP_Log
    fi
fi

sed '1,500 d' /var/log/ISP_Log

The log file contents:

CONNECTION:[YES] 2017-08-09 19:03:29
CONNECTION:[N/A] 2017-08-11 21:10:01
CONNECTION:[YES] 2017-08-11 21:15:02
CONNECTION:[N/A] 2017-08-12 20:40:01
CONNECTION:[YES] 2017-08-13 10:45:01