This way your script will look for the patterns in order as opposed to getting confused as to when to send what (especially since three of the patterns you're trying to match are exactly the same). If you want to change the pattern matching from string to regex, you only need to change the following in the do_exp sub:my $exp; foreach (@hosts) { $exp = Expect->spawn("ssh -l $username $_") or die "Cannot spawn ssh: $!\n"; do_exp ($timeout, 'password $', $oldpass); do_exp ($timeout, "$username\]", 'passwd'); do_exp ($timeout, 'password:', $oldpass); do_exp ($timeout, 'password:', $newpass); do_exp ($timeout, 'password:', $newpass); } sub do_exp { my ($_timeout, $_lookfor, $_send) = @_; if ($exp->expect($_timeout, $_lookfor)) { $exp->send($_send); } else { die "Timeout waiting for $_lookfor.\n"; } }
to:if ($exp->expect($_timeout, $_lookfor)) {
if ($exp->expect($_timeout,'-re',$_lookfor)) {
In reply to Re: Changing passwords using Expect.pm through ssh on a large number (75) of systems
by sschneid
in thread Changing passwords using Expect.pm through ssh on a large number (75) of systems
by linebacker
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |