Hi all, I got the solution for this problem..........the reason is that the new expect object had to be created for each machine that is
$exp = new Expect has to be inside the foreach loop, in my earlier code it was outside the foreach loop.....Thanks you all for the solutions......i tried using Net::SSH2 and Net::SSH::Perl and it didn't work for me so i had to use expect. Thanks On Tue, Jan 5, 2010 at 8:30 PM, Salvador Fandino <sfand...@yahoo.com> wrote: > 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 >