Posted by: kezhong | December 21, 2010

A script that can find the domains cannot be resolved by our DNS server

Our company wanted to know which domains cannot be resolved by our DNS server. I wrote a script as below, and added it to cron job to report me everyday.

#!/bin/bash

if ! test -e /tmp/qaz
then
    touch /tmp/qaz
fi
cat /dev/null > /tmp/qaz2

cat /var/log/messages|grep “unexpected RCODE (SERVFAIL) resolving”|awk ‘{print $10}’|cut -d: -f1|grep “A/IN”|cut -d\’ -f2|cut -d\/ -f1|sort|uniq|grep -v “in-addr.arpa” > /tmp/qaz1
for i in `cat /tmp/qaz1`
do
    if ! grep $i /tmp/qaz > /dev/null
    then
        if  ! dig $i |grep “ANSWER SECTION” > /dev/null
        then
            echo $i >> /tmp/qaz2
        fi
    fi
done

if [ -s /tmp/qaz2 ]
then
    cat /tmp/qaz2 >> /tmp/qaz
    mail -s “The domains that our DNS server could not resolve” steven_lkz@yahoo.com < /tmp/qaz2
fi


Responses

  1. Hey, I just wanted to share a cheaper web host with you… I know how hard it is to find a good cheap website host. http://www.wildgriffinmedia.com


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: