use warnings; use strict; open STATUS_DAT, "$filename"; print CONFIG $config; print "Wrote $filename\n"; } while () { $hs = 1, next if (/hoststatus/); $hs = 0, $r = 0, next if ($hs and /}/); next if (not $hs); $r = 1, $r_name = $+, next if (/host_name=(.*ROU)\n/); next if (not $r); $r_ip = $+, push @routers, [$r_name, $r_ip] if (/_PUBLICIP=[01];(.*)\n/); } for my $router (@routers) { my $retries = 0; retry: my $output = `expect -f show_running_config.exp $router->[$IP]`; if ($? == 0) { write_config($output, "$router->[$NAME].cfg"); } else { if ($retries <= 3) { sleep 5; $retries++; goto retry; } else { print "Failed to get config for $router->[$NAME] at $router->[$IP]: $output\n"; } } } #### for my $router (@routers) { my $retries = 0; while ($retries <= 3) { my $output = `expect -f show_running_config.exp $router->[$IP]`; write_config($output, "$router->[$NAME].cfg"), last if ($? == 0); } continue { sleep 5; $retries++; } if ($retries > 3) { print "Failed to get config for $router->[$NAME] at $router->[$IP]: $output\n"; } }