inventory.pl #!/usr/bin/perl # # inventory.pl -- a script to extract valuable information # from a Router. (Name, Location, Contact, S/N) # # # Set behaviour $workingdir="/home/nms"; $snmpro="ORARO"; $rtrlist="$workingdir/RTR_LIST"; # # open (RTR, "$rtrlist") || die "Can't open $rtrlist file"; open (LOG, ">$workingdir/RESULT") || die "Can't open $workingdir/RESULT file"; printf " Router\t\t Location\t\t\tContact\t\t Serial\n"; printf LOG " Router\t\t; Location\t\t\t;Contact\t\t ;Serial\n"; while () { chomp($rtr="$_"); $snmpget="/usr/local/bin/snmpget -v1 –c $snmpro $rtr "; $rtr=`$snmpget .1.3.6.1.4.1.9.2.1.3.0`; $loc=`$snmpget .1.3.6.1.2.1.1.6.0`; $con=`$snmpget .1.3.6.1.2.1.1.4.0`; $sin=`$snmpget .1.3.6.1.4.1.9.3.6.3.0`; chomp(($foo, $RTR) = split (/"/, $rtr)); chomp(($foo, $LOC) = split (/= /, $loc)); chomp(($foo, $CON) = split (/= /, $con)); chomp(($foo, $SIN) = split (/"/, $sin)); printf ("%-12.12s %-30.30s %-25.25s %-12.12s\n", $RTR, $LOC, $CON, $SIN); printf LOG ("%-12.12s; %-30.30s; %-25.25s; %-12.12s\n", $RTR, $LOC, $CON, $SIN); }