perl_haxor 123 wrote:
Hi All,
I'm new to perl and facing a problem........ I'm using a perl
expect script to login to multiple machines (having same username and
password) and execute the date command, initially i tested on one machine,
it worked fine...........but when i use a foreach loop to test the same
thing on two machines (the code is shown below), it didn't work.......it
just worked on the first machine (10.10.10.1) ........can someone please
help me out with this problem?......how can i use the perl expect script to
login to the multiple machines (assuming they have same username and
password) and execute commands?.. Kindly help me with this problem
There are several CPAN modules (Net::OpenSSH, Net::SSH2, Net::SSH::Perl,
Net::SSH::Expect) that allow to run commands in remote machines through
SSH. Any one of them will release you of the burden of handling
authentication and capturing the output of the remote command.
For instance:
use Net::OpenSSH;
for my $host (@hosts) {
my $ssh = Net::OpenSSH->new($host, user => $user, passwd => $passwd);
if ($ssh->error) {
warn "unable to connect to $host: ". $ssh->error;
next;
}
my $date = $ssh->capture('date');
print "$host: $date";
}
- Salva
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/