Created
March 29, 2020 21:27
-
-
Save kown7/91999c0a279ab17e7b359c94e1796c68 to your computer and use it in GitHub Desktop.
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
#!/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: [email protected] | |
Subject: IPv4 Address | |
From: [email protected] | |
Current IP address: ${ipaddr}" | sendmail -v [email protected] | |
echo $ipaddr > /tmp/ipv4.log | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment