Skip to content

Instantly share code, notes, and snippets.

@QueuingKoala
Created November 8, 2013 23:27
Show Gist options
  • Save QueuingKoala/7379291 to your computer and use it in GitHub Desktop.
Save QueuingKoala/7379291 to your computer and use it in GitHub Desktop.
SOA Update Monitor
#!/bin/sh
usage() {
printf "%s\n" "
$0 Usage:
Mandatory params:
--serial=X set SOA serial to watch for
--nameserver=NS set nameserver to query
--domain=X set domain to query SOA for
Optional params:
--delay=s seconds to delay for, default=300 (5 minutes)
--logfail=y/n y/n value to log failures
"
exit 99
}
die() {
printf "%s\n" "Fatal: $1"
exit ${2:-1}
}
# defaults:
DELAY=300
LOGFAIL=n
while [ -n "$1" ]; do
cmd="${1%=*}"
v="${1#*=}"
case "$cmd" in
--help|-h|help|-help) usage ;;
--serial) SERIAL="$v" ;;
--nameserver) NS="$v" ;;
--domain) DOMAIN="$v" ;;
--delay) DELAY="$v" ;;
--logfail)
case "$v" in
y) LOGFAIL=y ;;
n) LOGFAIL=n ;;
*) die "Invalid value for --logfail: $v (needs y or n)" ;;
esac
esac
shift
done
[ -n "$SERIAL" ] || die "Missing serial"
[ -n "$NS" ] || die "Missing nameserver"
[ -n "$DOMAIN" ] || die "Missing domain"
check_output() {
if grep -Eq ".*SOA.* $SERIAL .*"; then
printf "%s\n" "$(date) SUCCESS: SOA matched $SERIAL"
return 0
fi
[ "$LOGFAIL" = "y" ] && \
printf "%s\n" "$(date) NO MATCH"
return 1
}
# Main loop
printf "%s\n\n" \
"Starting up watching $DOMAIN for $SERIAL at $NS with delay $DELAY"
while :; do
dig "@$NS" SOA "$DOMAIN" 2>/dev/null | check_output && exit 0
sleep $DELAY
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment