my $router_data = [
{
routerName => 'asr01',
ipAddr => '1.1.1.1',
},
{
routerName => 'asr02',
ipAddr => '2.2.2.2',
},
];
####
for my $router ( @$router_data ) {
my $tty;
### Create SSH Session
print "\n" . "Logging into $router->{routerName}..." . " \n";
my $ssh = Net::SSH::Expect->new (
host => $router->{routerName},
password=> $pWord,
user => $uName,
timeout => '3',
raw_pty => 1
);
### Logon to the Router
$tty = $ssh->login();
if($tty !~ /$router->{routerName}/) {
die "Error: no prompt received.\n\n";
}
if ( $Action eq 'status' ) {
checkStatus($router->{routerName});
}
sub checkStatus {
my $routerName = $_[0];
my $test;
if ($routerName eq 'asr01') {
$test = $ssh->exec("show run | in hostname ");
} else {
$test = $ssh->exec("show clock");
}
print $test;
}
}
####
$ ./test.pl status
Logging into asr01...
show run | in hostname
hostname asr01
asr01#
Logging into asr02...
show clock
16:48:30.421 UTC Thu Jul 4 2013
asr01#