I modified per your recommendation:
#!/usr/bin/perl -w use strict; use Expect; my $timeout = '5'; my $username = 'luser'; my $newpass = 'luser'; my $oldpass = 'n3wp@ss!'; open(HOSTS,"hosts.txt") or die "Error while opening file:$!\n"; chomp( my @hosts = <HOSTS> ); close(HOSTS) or die "Error while closing file:$!\n"; my $exp; foreach (@hosts) { $exp = Expect->spawn("ssh -l $username $_") or die "Cannot spawn ssh: $!\n";; my $spawn_ok; #$exp->exp_internal(1); do_exp ($timeout, 'password', $oldpass); do_exp ($timeout, "$username\n", "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,'-re',$_lookfor)) { $exp->send($_send); } else { die "Timeout waiting for $_lookfor.\n"; } }

but am still having problems.
I show the output with verbose debugging turned on below:
Starting EXPECT pattern matching... Expect::expect('Expect=GLOB(0x835f7e0)', 5, '-re', 'password') cal +led at ./example.pl line 30 main::do_exp(5, 'password', 'n3wp@ss!') called at ./example.pl lin +e 21 spawn id(3): list of patterns: #1: -re `password' spawn id(3): Does `' match: pattern #1: -re `password'? No. luser@10.10.10.39's password: spawn id(3): Does `luser@10.10.10.39\'s password: ' match: pattern #1: -re `password'? YES!! Before match string: `luser@10.10.10.39\'s ' Match string: `password' After match string: `: ' Matchlist: () Sending 'n3wp@ss!' to spawn id(3) Expect::print('Expect=GLOB(0x835f7e0)', 'n3wp@ss!') called at ./ex +ample.pl line 30 main::do_exp(5, 'password', 'n3wp@ss!') called at ./example.pl lin +e 21 Starting EXPECT pattern matching... Expect::expect('Expect=GLOB(0x835f7e0)', 5, '-re', 'luser^J') call +ed at ./example.pl line 30 main::do_exp(5, 'luser^J', 'passwd') called at ./example.pl line 2 +2 spawn id(3): list of patterns: #1: -re `luser\n' spawn id(3): Does `: ' match: pattern #1: -re `luser\n'? No. n3wp@ss! spawn id(3): Does `: n3wp@ss!' match: pattern #1: -re `luser\n'? No. Timeout waiting for luser

Without verbose debugging:
luser@10.10.10.39's password: n3wp@ss!Timeout waiting for luser .
Thanks again for the assist!

In reply to Re: Re: Changing passwords using Expect.pm through ssh on a large number (75) of systems by linebacker
in thread Changing passwords using Expect.pm through ssh on a large number (75) of systems by linebacker

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.