Skip to content

Instantly share code, notes, and snippets.

@C-Stevens
Last active December 29, 2015 12:39
Show Gist options
  • Save C-Stevens/7672281 to your computer and use it in GitHub Desktop.
Save C-Stevens/7672281 to your computer and use it in GitHub Desktop.
Bash script (to be run periodically by cron) to check for external IP address changes. If any, emails the specified email of the change, and what the machine's new external IP is.
#!/bin/bash
##Required/recommended packages:
# mailutils
# msmtp
# msmtp-mta
currentIp=$(cat ~/ip.log)
grabbedIp=$(wget -O - -q -nv --delete-after www.icanhazip.com)
email="mail@yourdomain.com"
if [ "$currentIp" != "$grabbedIp" -n -a "$grabbedIp" ] ;
then
echo -e As of $(date): '\n'IP address has changed from $currentIp to $grabbedIp | mail -s "IP ADDRESS CHANGE" $email
echo $grabbedIp > ~/ip.log
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment