You probably want something like the following (untested) code:
#!/usr/bin/perl use strict; use warnings; use Net::Appliance::Session; my @ipconadd = qw(1.1.1.1 2.2.2.2 3.3.3.3); doStuff($_) for @ipconadd; sub doStuff { my ($host) = @_; eval { my $session = Net::Appliance::Session->new( { personality => 'ios', transport => 'SSH', host => $host } ); $session->connect({username => 'admin', password => 'coolbro'} +); $session->begin_privileged({password => 'verycoolbro'}); print $session->cmd('show hostname'); print $session->cmd('show inventory | i SN'); $session->end_privileged; $session->close(); return 1; } or do { my $err = $@; warn "Failed to doStuff for '$host': $@\n"; }; }
Note the for loop over hosts that calls the sub to do stuff. The loop could be written long hand as:
for my $host (@ipconadd) { doStuff($host); }
In reply to Re: read IPv4 addresses from array
by GrandFather
in thread read IPv4 addresses from array
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |