Last active
December 29, 2015 12:39
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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