Last active
August 29, 2015 14:12
-
-
Save lucachr/af2f1f4d448469453fa2 to your computer and use it in GitHub Desktop.
A bash script to notify changes of your ip address with an email
This file contains 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 | |
# Run this script in the background with './checkip.sh >/dev/null 2>&1 &' | |
# mail or mailx have to be configured by placing a .mailrc file in | |
# your home directory. | |
# The file where the current ip is saved | |
IPFILE='ipfile' | |
# Change this with your own email | |
MAILTO='example@example.com' | |
while true; do | |
newip=$(dig +short myip.opendns.com @resolver1.opendns.com) | |
oldip=$(cat $ipfile) | |
if [[ "$newip" != "$oldip" ]]; then | |
echo "The new ip is $newip" | |
echo $newip | mail -s 'Your ip has changed' $MAILTO | |
echo $newip >$IPFILE | |
fi | |
sleep 30 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment