Commit 39acf3fa authored by Mike Hibler's avatar Mike Hibler
Browse files

Make more robust.

Don't exit on individual failures, watch for case of switch disconneting
uncleanly from ssh.
parent 4474c18a
#!/usr/bin/perl #!/usr/bin/perl
# #
# Copyright (c) 2005-2016 University of Utah and the Flux Group. # Copyright (c) 2005-2017 University of Utah and the Flux Group.
# #
# {{{EMULAB-LICENSE # {{{EMULAB-LICENSE
# #
...@@ -65,27 +65,42 @@ foreach my $switch (@ARGV) { ...@@ -65,27 +65,42 @@ foreach my $switch (@ARGV) {
# #
# Is it a Cisco or maybe an HP # Is it a Cisco or maybe an HP
my $type = getDeviceType($switch); my $type = getDeviceType($switch);
if ($type !~ /cisco/ && $type !~ /catalyst/ && $type !~ /hp/ && $type !~ /force10/ ) { if ($type !~ /(cisco|catalyst|hp|force10)/) {
die " *** $0:\n" . print STDERR
" only Cisco and Procurves supported NOT (type $type)\n"; " *** $0:\n" .
" ignoring unsupported switch type (type $type)\n";
next;
} }
if ($type =~ /cisco/ || $type =~ /catalyst/ ) { if ($type =~ /(cisco|catalyst)/) {
system "$GRAB $switch $TMPFILE" if (system("$GRAB $switch $TMPFILE")) {
and die "Unable to grab config for $switch\n"; print STDERR "Unable to grab config for $switch, ignored\n";
system "mv $TMPFILE $BACKUPDIR/$switch-$datestr\n" next;
and die "Unable to move config file to $BACKUPDIR/$switch-$datestr\n"; }
if (system("mv $TMPFILE $BACKUPDIR/$switch-$datestr")) {
unlink($TMPFILE);
print STDERR "Unable to move config file to $BACKUPDIR/$switch-$datestr, ignored\n";
next;
}
} }
if ($type =~ /hp/ ) { if ($type =~ /hp/) {
system "scp $switch:/cfg/running-config $BACKUPDIR/$switch-$datestr\n" if (system("scp $switch:/cfg/running-config $BACKUPDIR/$switch-$datestr")) {
and die "Unable to grab and save config for $switch\n" print STDERR "Unable to grab and save config for $switch, ignored\n";
next;
}
} }
if ($type =~ /force10/ ) { if ($type =~ /force10/) {
system "ssh toor\@$switch write terminal \> $BACKUPDIR/$switch.in\n" if (system("ssh toor\@$switch write terminal \> $BACKUPDIR/$switch.in")) {
and "Unable to grab and save config for $switch\n"; if (($? >> 8) != 255) {
system "egrep -v \\#\\|Current\\|SupportAssist $BACKUPDIR/$switch.in \> $BACKUPDIR/$switch-$datestr\n" print STDERR "Unable to grab and save config for $switch ($?), ignored\n";
and die "Unable to strip first and last lines for $switch\n"; next;
system "rm -f $BACKUPDIR/$switch.in\n" }
and die "rm $BACKUPDIR/$switch.in failed\n" }
if (system("egrep -v \\#\\|Current\\|SupportAssist $BACKUPDIR/$switch.in \> $BACKUPDIR/$switch-$datestr")) {
unlink("$BACKUPDIR/$switch.in");
print STDERR "Unable to strip first and last lines for $switch, ignored\n";
next;
}
unlink("$BACKUPDIR/$switch.in");
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment