Skip to content

Instantly share code, notes, and snippets.

@marcostolosa
Created October 20, 2018 07:56
Show Gist options
  • Save marcostolosa/8886a518b0e00e8c88a356aae576d4cc to your computer and use it in GitHub Desktop.
Save marcostolosa/8886a518b0e00e8c88a356aae576d4cc to your computer and use it in GitHub Desktop.
Receive an email when your IP changes
#!/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
@marcostolosa
Copy link
Author

Obviously you will need to configure the ssmtp to use the mail command.

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