Skip to content

Instantly share code, notes, and snippets.

@ilyaevseev
Last active May 3, 2016 07:35
Show Gist options
  • Save ilyaevseev/8df60e96cef52b259f00 to your computer and use it in GitHub Desktop.
Save ilyaevseev/8df60e96cef52b259f00 to your computer and use it in GitHub Desktop.
Domaincheck -- alert on DNS domain info changing.
#!/bin/sh
(
cd /usr/local/domaincheck || exit 1
mkdir -p state logs || exit 1
./domaincheck domains.txt state > logs/$(date +%Y%m%d-%H%M%S).log 2>&1
find logs/ -type f -name '*.log' -mtime +30 -delete
) 2>&1 | mail -E -s "Domaincheck Error" admins
#!/bin/sh
#
# Alert on DNS domain info changing.
#
# Requirements:
# - commands: host, mail, hg
# - "admins" mailbox or alias
#
# Written by ilya.evseev@gmail.com at Aug-2014.
#
#set -x # ..uncomment for debug!
test $# = 2 || { echo "Usage: $0 domain-list.txt /path/to/statedir/"; exit; }
domlist="$1" # ..textfile, one line = one domain
statedir="$2"
DNS_SERVERS="8.8.4.4 77.88.8.8 4.2.2.5" # ..google, yandex, level3
for ns in $DNS_SERVERS; do host -t any "ya.ru" && { ns_good="yes"; break; }; done
test -n "$ns_good" || { echo "nslookup ya.ru failed" | mail -s "Domaincheck Error" admins; exit 1; }
while read dom; do
dom=${dom%%#*} # ..strip comments
test -z "$dom" && continue
for ns in $DNS_SERVERS; do
host "$dom" "$ns"
host -t any "$dom" "$ns"
host -t ns "$dom" "$ns"
host -t mx "$dom" "$ns"
sleep 1
done 2>&1 | grep "^$dom " | sort | uniq > "$statedir/$dom.state" || exit 1
done < "$domlist"
cd "$statedir/" || exit 1
test -d ".hg" || hg init || exit 1 # ..Requires Mercirial!
hg status | grep -q '' || exit 0 # ..nothing changed
( hg status ; hg diff ) | mail -s "Domaincheck report" admins
hg addremove
hg commit -m "Autocommit $(date '+%Y.%m.%d_%H:%M:%S')"
#!/bin/sh
test $# = 1 || { echo "Usage: $0 sitelist.txt"; exit; }
sitelist="$1" # ..textfile, one line = one sitename
wget -SO/dev/null "http://ya.ru/" 2>&1 | grep -qi '200 OK' ||
{ echo "ya.ru unavailable" | mail -s "Sitecheck blocked" admins; exit 1; }
while read site; do
site=${site%%#*} # ..strip comments
test -z "$site" && continue
state="$(wget -SO/dev/null "$site" 2>&1)"
echo $state | grep -qi '200 OK' && continue
echo $state | mail -s "Sitecheck failed: $site" admins
done < "$sitelist"
exit 0
#!/bin/sh
test $# = 1 || { echo "Usage: $0 domain-list.txt"; exit; }
domlist="$1" # ..textfile, one line = one domain
while read dom; do
dom=${dom%%#*} # ..strip comments
test -z "$dom" && continue
d="$(whois $dom | awk '/[Ee]xpir.*[Dd]ate:/ || /[Tt]ill:/ {print $NF; exit;}')"
if test -z "$d"; then
echo "Empty expiration time for $dom" | mail -s "Whoischeck error" admins
continue
fi
ds="$(date --date="$d" +%Y.%m.%d 2>/dev/null)"
test -n "$ds" || ds="$d" # ..workaround hack, unrecognized date may be already in "yyyy.mm.dd" format!
if test -n "${ds##????.??.??}"; then # ..check for "yyyy.mm.dd" format
echo "Wrong expiration time for $dom: $d" | mail -s "Whoischeck error" admins
continue
fi
#printf "%20s: %s\n" "$dom" "$ds"
for x in `seq 0 29`; do
soon=`date --date="+$x days" +%Y.%m.%d`
test "$ds" = "$soon" || continue
echo $dom: $ds | mail -s "Time to pay for domain" admins
break;
done
done < "$domlist"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment