snmpcfg.pl 1.78 KB
Newer Older
O'Reilly Media, Inc.'s avatar
O'Reilly Media, Inc. committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
snmpcfg.pl
#!/usr/bin/perl -w
#
#    snmpcfg.pl -- a script to perform mass configuration changes to
#                  a list of routers using SNMP.
#
#
# Set behaviour
$workingdir="/home/nms";
$snmprw="ORARW";
$tftpsrv="172.25.1.1";
#
#
$rtrlist="$workingdir/RTR_LIST";
open (RTR, "$rtrlist") || die "Can't open $rtrlist file";
open (LOG, ">$workingdir/RESULT") || die "Can't open $workingdir/RESULT file";
#
while (<RTR>) {
  chomp($rtr="$_");
  print LOG "=================================== \n";
  print "=================================== \n";
  $snmpset="/usr/local/bin/snmpset -t 20 -r 2 v1 c $snmprw $rtr ";
  chomp($result=`$snmpset .1.3.6.1.4.1.9.2.1.50.$tftpsrv s SNMPCFG`);
  if ($result=~/.+ = "(.+)"$/ ) {
            if( $1 eq SNMPCFG ) {
                print LOG "$rtr - Update Successful\n";
                print "$rtr - Update Successful\n";
                chomp($result=`$snmpset .1.3.6.1.4.1.9.2.1.54.0 i 1`);
                if ($result=~/.+ = (.+)$/ ) {
                          if( $1 == 1 ) {
                            print LOG "$rtr - Wr Mem Successful\n";
                            print "$rtr - Wr Mem Successful\n";
                          }
                          else {
                            print LOG "$rtr - Wr Mem Failed\n";
                            print "$rtr - Wr Mem Failed\n";
                          }
                }
                else {
                  print LOG "$rtr - Wr Mem Failed\n";
                  print "$rtr - Wr Mem Failed\n";
                }
            }
            else {
              print LOG "$rtr - Update Failed\n";
              print "$rtr - Update Failed\n";
            }
  }
  else {
    print LOG "$rtr - Update Failed\n";
    print "$rtr - Update Failed\n";
  }
}