Skip to content

Instantly share code, notes, and snippets.

@jeffskinnerbox
Created February 7, 2016 17:37
Show Gist options
  • Save jeffskinnerbox/fd4c1ea2f22a361f4164 to your computer and use it in GitHub Desktop.
Save jeffskinnerbox/fd4c1ea2f22a361f4164 to your computer and use it in GitHub Desktop.
This utility is used to periodically check to see if the external IP address has changed, and if so, send a notification giving the new IP address.
#!/bin/bash
# This utility is used to periodically check to see if the external IP address
# has changed, and if so, send a notification giving the new IP address.
#
# Reasons why crontab does not work - http://askubuntu.com/questions/23009/reasons-why-crontab-does-not-work
FLAG=0 # set to 1 for verbose output
MYPATH="/home/jeff/bin" # path to apprise, need for running in cron
# Parse command line options
USAGE="Usage: `basename $0` [-h] [-x]"
while getopts hx OPT; do
case "$OPT" in
h)
echo $USAGE
exit 0
;;
x)
FLAG=1
;;
\?)
# getopts issues an error message
echo $USAGE >&2
exit 1
;;
esac
done
# get current and old IP address
IP_ADDRESS_STORE=$HOME/.external_ip_address
CURRENT_IP=$(cat $IP_ADDRESS_STORE)
NEW_IP=$(curl --silent ifconfig.co)
# send message about any changes
if [ $CURRENT_IP == $NEW_IP ];
then
if [ $FLAG -eq 1 ];
then
$MYPATH/apprise -t "External IP Address" -m "No change in home router external IP address ($CURRENT_IP)."
fi
exit 2
else
echo $NEW_IP > $IP_ADDRESS_STORE
$MYPATH/apprise -t "External IP Address" -m "Your home router external IP address has changed from $CURRENT_IP to $NEW_IP."
exit 3
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment