Skip to content

Instantly share code, notes, and snippets.

@tibu
Forked from wei/whois-watch.sh
Created August 4, 2017 13:26
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 tibu/2a0982a78c22ffacc8154106bb24137a to your computer and use it in GitHub Desktop.
Save tibu/2a0982a78c22ffacc8154106bb24137a to your computer and use it in GitHub Desktop.
Monitor whois changes
#!/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