#!/usr/bin/perl use Net::Telnet; # # Use telnet and the "configshow" command to backup brocade switch # configurations. Telnet to each switch in the list and run configshow # then write the output to /home/config/MonthYear/swcfg-hostname.txt # # You will need to edit this script to your custom switch name list # user id, and password. Or those can be specified on the command line. # # V1.0 Dec 2011 Andy Welter based on sw-runcmd script # # # Net::Telnet example: # to send commands use # $telnet->print('somecommand'); # $output=$telnet->waitfor('/\$ /'); # or # $output=$telnet->cmd ('somecommand'); # my $usage='sw-savecfg <-u user> <-p password> <-s "switchname1 switchname2 ...">'; use Getopt::Std; if ( getopts ('s:u:p:') == 0) { print "$usage\n"; exit 1; }; $user=$opt_u; $passwd=$opt_p; $cmd=$opt_c; if ( $opt_s eq "" ) { $opt_s="fabasw1 fabasw2 fabbsw1 fabbsw2"; chomp $opt_s; }; @hostlist=split /\s+/,$opt_s; if ( $user eq "" ) { $user="admin"; }; if ( $passwd eq "" ) { $passwd="YourReallSecurePassword"; chomp $passwd; }; my $cmd="configshow -all"; # # Construct the directory name for the save location. my @months=("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"); my @dtime=localtime(time()); my $dir=sprintf ("/home/config/%s%d",$months[$dtime[4]],$dtime[5]+1900); foreach $host (@hostlist) { print "\n##########\n## system: $host \ncommand: $cmd\n##########\n"; $telnet = new Net::Telnet (Timeout=>20, Prompt=>'/\> /', Errmode=>'return'); my @output; if ($telnet->open ($host)) { if ($telnet->login ($user,$passwd)) { open (CFG, "> $dir/swcfg-$host.txt") || die "Cannot open $dir/swcfg-$host.txt\n"; @output=$telnet->cmd ($cmd); # # remove the last output line from the output. That will be a command prompt. pop @output; print CFG @output; close CFG; $telnet->print ('exit'); } else { print "login failed for $host\n"; }; } else { print "open failed for $host\n"; }; $telnet->close(); print "\n"; };