From 064edd67e0535f01a98282505e34ce02eb03befa Mon Sep 17 00:00:00 2001 From: F3RR3T Date: Sun, 24 Aug 2014 14:26:51 +1000 Subject: Interim stage. Monitor script logs every 30 mins. compare.sh has some test file reading and comparison functions But the time has come to wrap it all into one script. This will be called monitor.sh --- compare.sh | 38 ++++++++++++++++++++++++++++++++++++++ monitor.sh | 8 ++++++-- readme.md | 0 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100755 compare.sh delete mode 100644 readme.md diff --git a/compare.sh b/compare.sh new file mode 100755 index 0000000..1db6a21 --- /dev/null +++ b/compare.sh @@ -0,0 +1,38 @@ +#!/bin/bash - +# SJP August 2014 +# Reads logfile of IP address records created by monitor.sh +# When IP address changes it sends an email" + + +cd ~/mail/monitor + +if (test -e data/tmp.*) then + datafile=$(ls data/tmp.*) +else + exit +fi + + +#i=0 +#while read line +#do +# i=$[i+1] +# echo $i, $line +#done < $datafile + +# Get the IP address from the first line +read firstline < $datafile + +firstip=$(echo $firstline | awk '{ print $2 }') + +# sec=$(echo $firstline | awk '{ print $1 }') + +echo "First = $firstip" + +lastline=$(tail -1 $datafile) + +lastip=$(echo $lastline | awk '{ print $2 }') + +echo "Last = $lastip" + +[ "$lastip" = "$firstip" ] && echo 'match' || echo 'different' diff --git a/monitor.sh b/monitor.sh index e902c86..bebc07c 100755 --- a/monitor.sh +++ b/monitor.sh @@ -1,4 +1,4 @@ -#! /bin/sh - +#! /bin/bash - # SJP 16 August 2014 # Monitor my external IP address @@ -13,11 +13,15 @@ else datafile=`mktemp --tmpdir=data` fi -echo "datafile = $datafile" +# echo "datafile = $datafile" ip=$(curl ifconfig.me/ip) +[ ${#ip} = 0 ] && ip="Timed out" +# Could also do [ -z $ip ] + dt=$(\date +%Y-%m-%dT%T%:z) + echo -e "$dt\t$ip" >> $datafile diff --git a/readme.md b/readme.md deleted file mode 100644 index e69de29..0000000 -- cgit v1.3