Created
July 10, 2018 18:26
-
-
Save nisargshah95/50f5085d42d02be8d3d820ae59fd748f to your computer and use it in GitHub Desktop.
Send an email whenever public IP address changes
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
# The script sends an email with updated IP address | |
# whenever there is an IP change from ISP | |
MSG="To: [email protected]\nFrom: [email protected]\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 [email protected] | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Related blog post - https://forkedprocess.wordpress.com/2018/04/23/connecting-remotely-via-ssh-vnc/