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

Make more robust.

Don't exit on individual failures, watch for case of switch disconneting
uncleanly from ssh.
parent 4474c18a
#!/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
#
......@@ -65,27 +65,42 @@ foreach my $switch (@ARGV) {
#
# Is it a Cisco or maybe an HP
my $type = getDeviceType($switch);
if ($type !~ /cisco/ && $type !~ /catalyst/ && $type !~ /hp/ && $type !~ /force10/ ) {
die " *** $0:\n" .
" only Cisco and Procurves supported NOT (type $type)\n";
if ($type !~ /(cisco|catalyst|hp|force10)/) {
print STDERR
" *** $0:\n" .
" ignoring unsupported switch type (type $type)\n";
next;
}
if ($type =~ /cisco/ || $type =~ /catalyst/ ) {
system "$GRAB $switch $TMPFILE"
and die "Unable to grab config for $switch\n";
system "mv $TMPFILE $BACKUPDIR/$switch-$datestr\n"
and die "Unable to move config file to $BACKUPDIR/$switch-$datestr\n";
if ($type =~ /(cisco|catalyst)/) {
if (system("$GRAB $switch $TMPFILE")) {
print STDERR "Unable to grab config for $switch, ignored\n";
next;
}
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/ ) {
system "scp $switch:/cfg/running-config $BACKUPDIR/$switch-$datestr\n"
and die "Unable to grab and save config for $switch\n"
if ($type =~ /hp/) {
if (system("scp $switch:/cfg/running-config $BACKUPDIR/$switch-$datestr")) {
print STDERR "Unable to grab and save config for $switch, ignored\n";
next;
}
}
if ($type =~ /force10/ ) {
system "ssh toor\@$switch write terminal \> $BACKUPDIR/$switch.in\n"
and "Unable to grab and save config for $switch\n";
system "egrep -v \\#\\|Current\\|SupportAssist $BACKUPDIR/$switch.in \> $BACKUPDIR/$switch-$datestr\n"
and die "Unable to strip first and last lines for $switch\n";
system "rm -f $BACKUPDIR/$switch.in\n"
and die "rm $BACKUPDIR/$switch.in failed\n"
if ($type =~ /force10/) {
if (system("ssh toor\@$switch write terminal \> $BACKUPDIR/$switch.in")) {
if (($? >> 8) != 255) {
print STDERR "Unable to grab and save config for $switch ($?), ignored\n";
next;
}
}
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