Rounding Up Computers

Today I was given a list of computers that SMS could not contact, most likely the DNS setting was incorrect. So here are the scripts I used to diagnose the problem.

First I wrote a little script that looks for the computer name in our DNS directories, I called it ng, short for named grep, here it is:

[code lang=”bash”]
#!/bin/bash

# 2007-09-19 Jud Bishop
# ng short for namedgrep. Does a case insensitive
# search for the hostname
# supplied at the command line.

if [ -z $1 ]
then
echo " Useage:$0 host "
exit
fi

grep -i $1 /var/named/internal/*
grep -i $1 /var/named/internal/172.25/*
# end script
[/code]

Next I was given a file with the hostname and error, the file was in this format:
[code]
prompt> cat tmp.txt
HOST1

Unable to retrieve computer information for ‘jlb18.circus.org’. Access is
denied.

HOSTIII

Unable to retrieve computer information for ‘jlbIII.circus.org’. Access is
denied.

HOST4

Unable to retrieve computer information for ‘jlb4.circus.org’. The network
path was not found.
/end tmp.txt
[/code]

So I ran this little on liner on it to edit out just the hostnames, the sed
joins two lines, thus eliminating the blank ones, cheap hack but it works:
[code]
promtp> cat tmp.txt |sed /^$/d |grep -v Unable >ng.in
[/code]

Now I have a files of hostnames, one per line that I can send into ng.
[code]
prompt> cat ng.in
HOST1
HOSTIII
HOST4
[/code]

Finally I just ran this from the command line:
[code]
prompt> for I in `cat ng.txt`; do echo $I; ng $I; done >ng.out
[/code]

And that was the first 20 minutes of work after reading my email this morning.

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply