-
-
Save tibu/2a0982a78c22ffacc8154106bb24137a to your computer and use it in GitHub Desktop.
Monitor whois 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
#!/bin/bash | |
# | |
# Run this script once per minute | |
# | |
# * * * * * /path/to/whois-watch.sh google.com apple.com >> /var/log/whois-watch.log 2>&1 | |
# update username in mail command | |
# update sed command depending on server return text | |
# | |
TMP_DIR="/tmp" | |
function TIMESTAMP() { | |
echo $(date -u +"%Y-%m-%d-%H:%M:%S") | |
} | |
NEWLINE=$'\n' | |
for DOMAIN in "$@" | |
do | |
echo "[whois-watch.sh][$(TIMESTAMP)] Checking whois for $DOMAIN" | |
OLD="$TMP_DIR/$DOMAIN.old.whois.txt" | |
NEW="$TMP_DIR/$DOMAIN.new.whois.txt" | |
DIFF="$TMP_DIR/$DOMAIN.whois.diff.txt" | |
if [ ! -f $OLD ]; then | |
echo "not available" > $OLD | |
fi | |
whois $DOMAIN -H | sed -e 's/^.*last update.*$//gI' > $NEW | |
OLDHASH=$(sha1sum $OLD | awk '{print $1}') | |
NEWHASH=$(sha1sum $NEW | awk '{print $1}') | |
if [ "$OLDHASH" != "$NEWHASH" ]; then | |
echo "[whois-watch.sh][$(TIMESTAMP)] $DOMAIN WHOIS Updated" | |
diff $NEW $OLD > $DIFF | |
mail -s "Whois information of $DOMAIN changed at $TIMESTAMP UTC" root < $DIFF | |
rm $DIFF | |
else | |
echo "[whois-watch.sh][$(TIMESTAMP)] $DOMAIN WHOIS Hasn't Changed" | |
fi | |
mv $NEW $OLD | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment