1844060 Members
3042 Online
110227 Solutions
New Discussion

Script

 
zsujith
Frequent Advisor

Script

Hi All,

I want to check netstat -rn output with /etc/r.config/netstat file. I want to check which route entry are missed in netstat file.
I want to check these steps in 50 servers

Could u help me to make a script for this?

Thanks
Sujith
"The most wasted day is that in which we have not laughed."
1 REPLY 1
Doug O'Leary
Honored Contributor

Re: Script

Hey;

Intriguing little puzzle, so I thought I'd give it a try.

The attached script first identifies the local IP addresses, then loops through the output of a netstat -rn command. If the gateway IP address isn't one of the NIC ip addresses, it looks for it in /etc/rc.config.d/netconf. It reports either way, but that's easy to change. I also left in the 127.0.0.1 to show what it'll look like when it doesn't find a route. In the production run, those should be filtered out as well.

The output looks something like the following (with some obfuscation for privacy/security):

# ./scan_routes | perl -i -ple 's/135.3.\d+/135.3.XX/g'
127.0.0.1 127.0.0.1 NOT listed in /etc/rc.config.d/netconf
135.3.XX.49 135.3.XX.49 was found as a nic route
135.3.XX.115 135.3.XX.115 was found as a nic route
135.3.XX.125 135.3.XX.125 was found as a nic route
135.3.XX.0 135.3.XX.125 was found as a nic route
135.3.XX.0 135.3.XX.115 was found as a nic route
135.3.XX.0 135.3.XX.49 was found as a nic route
127.0.0.0 127.0.0.1 NOT listed in /etc/rc.config.d/netconf

As for running it on X number of hosts, make sure you have ssh set up correction using public key authentication (*LOTS* of references to that in these forums) then:

for h in $(cat file_w_hostname)
do
echo "### ${h} ###"
ssh ${h} /tmp/scan_networks
done

or something equally clever.

HTH;

Doug O'Leary

------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html