#!/bin/bash
# wanstatus: Monitor WideAreaNetwork status for disconnections
# After testing make this script a startup application
# sleep 5 minutes (300 seconds)to be sure internet connection is established
#sleep 300
cd /home/mike/Documents
# set start name of wanstatus log (in Documents folder)
logfile="logfile"
logfile=wanstatuslog-$(date +%Y%m%d)-$(date +%H%M%S)
echo "Wide Area Network status log to record disconnections by change of IP address." >> $logfile
echo "================================================= =============================" >> $logfile
# start loop here?
while [ 1 = 1 ]
do
# sleep 1 minute (60 seconds) before obtaining IP address again
#sleep 60
sleep 1 # just sleep 1 second for test purposes
# assign dated value to variable logtime and put my public IP address alongside the time in the logfile
lineout="Date and Time: "
logtime=$(date +%Y%m%d)-$(date +%H%M%S) # date and time
ip=" IP address: "
lineout="$lineout $logtime $ip"
echo $lineout >> $logfile
curl ifconfig.me >> ipaddress
cat ipaddress >> $logfile
rm ipaddress
done
#next to do
# ? How do find out when IP address changes after an internet disconnect/reconnect ?
exit
Bookmarks