From c4f7ca2241c28f801589dafe9048a40109be86a8 Mon Sep 17 00:00:00 2001 From: Sonny Date: Wed, 9 May 2018 23:23:05 +0200 Subject: [PATCH] Add script to detect public ip address change --- scripts/detect-ip-change | 15 +++++++++++++++ scripts/pubip | 4 ---- 2 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 scripts/detect-ip-change delete mode 100755 scripts/pubip diff --git a/scripts/detect-ip-change b/scripts/detect-ip-change new file mode 100644 index 0000000..51a0ed6 --- /dev/null +++ b/scripts/detect-ip-change @@ -0,0 +1,15 @@ +#!/bin/bash +# Send an email when the public ipv4 address changes + +if [[ -a /tmp/ipv4_address ]]; then + CURRENT_IP=$(/usr/bin/dig +short myip.opendns.com @resolver1.opendns.com) + PREVIOUS_IP=$(cat /tmp/ipv4_address) + + if [[ $CURRENT_IP != $PREVIOUS_IP ]]; then + echo "IP address changed from $PREVIOUS_IP to $CURRENT_IP" | /usr/bin/mail -s 'IP address changed' sonnyba871@gmail.com + echo $CURRENT_IP > /tmp/ipv4_address + echo "Mail sent" + fi +else + echo "$(/home/sonny/dotfiles/scripts/pubip)" > /tmp/ipv4_address +fi diff --git a/scripts/pubip b/scripts/pubip deleted file mode 100755 index 7039c6f..0000000 --- a/scripts/pubip +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -## Get public IP - -wget http://ipinfo.io/ip -qO -