Skip to content

Instantly share code, notes, and snippets.

@kown7
Created March 29, 2020 21:27
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 kown7/91999c0a279ab17e7b359c94e1796c68 to your computer and use it in GitHub Desktop.
Save kown7/91999c0a279ab17e7b359c94e1796c68 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Send an e-mail with your IP address if it has changed
set +e
old_ipaddr=$(cat /tmp/ipv4.log)
set -e
get_ipv4()
{
# Return string with current IPv4 address
ipv4=$(dig TXT -4 +short o-o.myaddr.l.google.com @ns1.google.com |
awk -F'"' '{ print $2}')
echo "${ipv4}"
}
ipaddr=$(get_ipv4)
if [[ "$old_ipaddr" == "$ipaddr" ]]; then
exit 0
fi
echo "To: john.doe@gmail.com
Subject: IPv4 Address
From: cron@myhost.com
Current IP address: ${ipaddr}" | sendmail -v john.doe@gmail.com
echo $ipaddr > /tmp/ipv4.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment