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



#############################################################
#!/usr/bin/perl -w
use strict;
use Expect;


foreach ("10.10.10.1", "10.10.10.2") {
print "Spawning to the $_\n";
$exp->spawn("ssh -l username $_") or warn "unable to spawn: $!";



#This part checks for the password prompt, if it doesn't get the password
prompt the errors are displayed.
unless($exp->expect(10, '-re','.*password:\s*')){

if( $exp->before()) {
print $exp->before();
print "\n";
}
else {

print "Timed out\n";
}
next;
}


print "Sending password to the host\n";

$exp->send("password\r");
print "\n";


#This code will handle any errors after the password is sent

unless($exp->expect(10, '-re', '.*[#$>]')) {



if($exp->before() =~ /(Permission.*\s*.*)/) {
print "\n";
print "Invalid password\n";
}
else {

print "timed out\n";

}
exit;

}




print "sending date command\n";

$exp->send("date\r");
$exp->expect(15, '-re', '.*[#$>]' );
$exp->soft_close();

}
#############################################################

Reply via email to