Skip to content

Instantly share code, notes, and snippets.

@nisargshah95
Created July 10, 2018 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nisargshah95/50f5085d42d02be8d3d820ae59fd748f to your computer and use it in GitHub Desktop.
Save nisargshah95/50f5085d42d02be8d3d820ae59fd748f to your computer and use it in GitHub Desktop.
Send an email whenever public IP address changes
# The script sends an email with updated IP address
# whenever there is an IP change from ISP
MSG="To: myemail@gmail.com\nFrom: myemail@gmail.com\nSubject: New IP\n"
IP_FILE=/home/nisarg/ip-address.txt
IP=$(/usr/bin/dig +short myip.opendns.com @resolver1.opendns.com)
OLD_IP=$(cat $IP_FILE)
if [ "$IP" != "$OLD_IP" ]; then
echo $IP > $IP_FILE # save new IP to file
MSG="$MSG\n$IP\n" # add IP to message body
echo -e $MSG | /usr/sbin/ssmtp myemail@gmail.com
fi
@nisargshah95
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment