Created
October 20, 2018 07:56
-
-
Save marcostolosa/8886a518b0e00e8c88a356aae576d4cc to your computer and use it in GitHub Desktop.
Receive an email when your IP changes
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 | |
ip_file=~/.ip | |
if [ ! -f "$ip_file" ]; then touch $ip_file; fi | |
last=$(cat "$ip_file") | |
current=$(dig +short myip.opendns.com @resolver1.opendns.com) || exit | |
if [ "$last" = "$current" ]; then exit; fi | |
mail -s "[IP from Everywhere]" <your_email>@server.com <<< "$current" | |
if [ "$?" -eq 0 ]; then echo "$current" > "$ip_file"; fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Obviously you will need to configure the ssmtp to use the mail command.