From: Turenne, J. <Jon...@St...> - 2009-07-16 13:06:25
|
Good Morning, As a newbie to 'Expect', I am having a few issues with my script. Having integrated it with Perl, I have parts of it that are working, and parts that are not. In any event, can someone answer the following for me? 1. When inside an expect statement, are these generally 'conditions', and are they evaluated from top to bottom? 2. Is it possible to 'break' out of this expect statement once I meet a certain condition? In my example code, you will see that I have an "exp_return" statement which is not valid. Essentially, I need to break out of the expect statement, and move on to the next item in the foreach loop. Thanks in advance! I have been combing the web & docs, and really don't see how to do it. Plus, since I am still at the VERY early stages of learning this, I really don't know what I am looking for -- I just know what I want to do. Here is the code: foreach $Host (sort @Hosts) { $CantPingHost = 0; chomp(@PingResult = `ping -w $PingTime $Host`); foreach my $line (@PingResult) { if ($line =~ m/.*100\% packet loss.*/) { $UnsuccessCount++; $CantPingCountv++; $GeneratePingList = 1; $CantPingHost = 1; push @UnpingableHosts, $Host; print " Can't ping host: '$Host' Skiping...\n"; last; } } next if ($CantPingHost); print "Changing password on: $Host\n"; $exp = new Expect(); $exp->debug($DegugState); $exp->spawn("ssh -X $User\@$Host"); $exp->expect($Timeout, '-re', [".*continue connecting.*", sub {$exp->send("yes\r"); exp_continue;}], [".*$User.*assword:.*", sub {$exp->send("$OldPaswd\r"); exp_continue;}], [".*TERM = .*", sub {$exp->send("vt100\r"); exp_continue;}], [".*$Host\s*:.*", sub {$exp->send("$paswd\r"); exp_continue;}], [".*ld ?assword:.*", sub {$exp->send("$OldPaswd\r"); exp_continue;}], [".*ew ?assword.*", sub {$exp->send("$NewPaswd\r"); $exp->send("exit\r"); exp_continue;} ], [".*assword was recently used.*", sub {$exp->send("exit\r"); $RecentPswd = 1; $UnsuccessCount++; push @RecentPswdNodes, $Host; exp_return;}] ); $exp->soft_close(); $SuccessCount++; } |