summaryrefslogtreecommitdiff
path: root/monitor.sh
diff options
context:
space:
mode:
authorF3RR3T <github@st33v.com>2014-09-06 22:04:16 +1000
committerF3RR3T <github@st33v.com>2014-09-06 22:04:16 +1000
commite779a2afe559d67bef12bb57f1a4ce0de06b9c81 (patch)
treee75ae52ce5eb8019227ae5ab2b9d20c81fbb44bf /monitor.sh
parente90ead311dff1bccd50cbea8e2e915c185537e53 (diff)
Monitor now ckecks for IP change and invokes email notification
Diffstat (limited to 'monitor.sh')
-rwxr-xr-xmonitor.sh23
1 files changed, 20 insertions, 3 deletions
diff --git a/monitor.sh b/monitor.sh
index bebc07c..1bf5129 100755
--- a/monitor.sh
+++ b/monitor.sh
@@ -3,14 +3,16 @@
# SJP 16 August 2014
# Monitor my external IP address
-# set up logfile
cd ~/mail/monitor
+# set up logfile
if (test -e data/tmp.*) then
datafile=$(ls data/tmp.*)
+ newfile=0
else
datafile=`mktemp --tmpdir=data`
+ newfile=1
fi
# echo "datafile = $datafile"
@@ -18,10 +20,25 @@ fi
ip=$(curl ifconfig.me/ip)
[ ${#ip} = 0 ] && ip="Timed out"
# Could also do [ -z $ip ]
-
dt=$(\date +%Y-%m-%dT%T%:z)
+# either write date + IP to new file or compare IPs
+# write date and IP address to file but delete if it's a dud
+if (test "$newfile" -eq 1) then
+ echo -e "$dt\t$ip" > $datafile
+ [ "$ip" == "Timed out" ] && rm $datafile
+
+else # datafile already exists, so compare
+ read line < $datafile
+ oldip=$(echo $line | awk '{print $2 }')
+ if (test "$ip" != "$oldip") then
+ . notifynewip.sh
+ rm $datafile
+ fi
+fi
+
+
+
-echo -e "$dt\t$ip" >> $datafile