nickt9999 has asked for the wisdom of the Perl Monks concerning the following question:
Hi All,
Another one that I cant quite get my head around :-(
I have this hash
And this is the code: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; } }
For love nor money I cannot get the code to execute commands on asr02
Here the output I get
$ ./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#
As you can see it seems to be running both commands on asr01, I know it is logging into asr02 as the logs see a Login connection
All help appreciated.
Thanks
Nick
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: For loop and Sub Routines
by NetWallah (Canon) on Jul 04, 2013 at 17:07 UTC | |
by nickt9999 (Acolyte) on Jul 04, 2013 at 17:51 UTC | |
by NetWallah (Canon) on Jul 05, 2013 at 05:17 UTC | |
|
Re: For loop and Sub Routines
by shawnhcorey (Friar) on Jul 04, 2013 at 17:07 UTC |