Re: Backing up config

From: Kristian Bjørnskov (krbj-ccielab@novo.dk)
Date: Fri Dec 12 2003 - 05:35:35 GMT-3


JHays writes:
>
> Would you please post your Perl script? I for one would be interested.

We use perl and tftp from the switch/router. The "get config part" is below.
PIX'es and oter stuff we get from an expect script. The complete script is
quite ugly since it has been modified a cilion times. This is only the
"fetch" part. The script actually get the router names from a PGSql
database, fetch the configs, fetch the hardware configuration, fetch CDP
neighbors, fetch VTP table and a bunch of other stuff and move all of it to
a CVS repository.

/kristian

 ----

$tftpserver=
$name=
$ip=
$comname=
$type=`snmpget -m all $ip $comname 1.2.0`

if ($type =~ /cisco\.ciscoProducts/) {
             system "snmpset -m all -t5 -v1 $ip $comname
.1.3.6.1.4.1.9.2.1.55.$tftpserver s $name.new";
         if($? > 0) {
           print "ERROR: while talking to $name: $? $! on ip $ip\n";
           print "-- while executing snmpset -t5 -v1 $ip $comname
.1.3.6.1.4.1.9.2.1.55.$tftpserver s $name.new\n";
           return;
         };
         my $tryes=0;
         while ($tryes<10 and !$upload_ok) {
           open(FILEIN,"<$tftpboot/$name.new") or print "ERROR: $!\n";
           while (<FILEIN>) {
             $upload_ok=1 if (/^end$/);
           };
           close (FILEIN);
           $tryes++;
           print do_timestamp()." INFO: Tryed $tryes times.
upload_ok=$upload_ok\n";
           sleep 3 unless $upload_ok;
         }

 

      } elsif ($type =~ /cisco\.workgroup/) {
          system "snmpset -m all -t5 -v1 $ip $comname
.1.3.6.1.4.1.9.5.1.5.1.0 s $tftpserver";
          if($? > 0) {
            print do_timestamp()." ERROR: while talking to $name: $? $! on
ip $ip\n";
            print "-- while executing snmpset -t5 -v1 $ip $comname
.1.3.6.1.4.1.9.5.1.5.1.0 s $tftpserver\n";
            return;
          };
          system "snmpset -m all -t5 -v1 $ip $comname
.1.3.6.1.4.1.9.5.1.5.2.0 s $name.new";
          system "snmpset -m all -t5 -v1 $ip $comname
.1.3.6.1.4.1.9.5.1.5.3.0 i 1";
          system "snmpset -m all -t5 -v1 $ip $comname
.1.3.6.1.4.1.9.5.1.5.4.0 i 3";
          if($? > 0) {
            print do_timestamp()." ERROR: while talking to $name: $? $! on
ip $ip\n";
            print "-- while executing snmpset -t5 -v1 $ip $comname
.1.3.6.1.4.1.9.5.1.5.4.0 i 3\n";
            return;
          };
          my $tryes=0;
          while($tryes<10 and (($test=`snmpget -m all $ip $comname
.1.3.6.1.4.1.9.5.1.5.5.0`) =~ /.*\((\d+)\)/) && $1<2) {
             $tryes++;
             sleep(3);
             print do_timestamp()." INFO: try: $tryes : $test";
          }
          return if $?;
          print $test;
          if (($test =~ /.*\((\d+)\)/) && $1>2) {
             print do_timestamp()." WARNING: tftp from $name failed with
error $test";
             return;
          }
          return unless -s "$tftpboot/$name.new";
          open FILEIN, "<$tftpboot/$name.new";
          while (<FILEIN>) {
           $upload_ok=1 if (/^end$/);
          };
          close(FILEIN);
}



This archive was generated by hypermail 2.1.4 : Sat Jan 03 2004 - 08:25:39 GMT-3