Skip to content

Instantly share code, notes, and snippets.

@lucachr
Last active August 29, 2015 14:12
Show Gist options
  • Save lucachr/af2f1f4d448469453fa2 to your computer and use it in GitHub Desktop.
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
#!/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