After you run the script, run the following:
echo $?
Based on the change_password() subroutine, I expect you will get the value 1 back indicating there is an error and something doesn't match.
sub change_password {
my ($host, $ssh) = @_;
my ($pty) = $ssh->open2pty('passwd');
my $expect = Expect->init($pty);
$expect->raw_pty(1);
# $expect->log_user(1);
if (answer_passwd($expect, 'current.*:', $old) and
answer_passwd($expect, 'Enter new.*:', $new) and
answer_passwd($expect, 'Retype new.*:', $new) and
$expect->expect($timeout, "success")) {
exit(0);
}
exit(1);
}
Also, I'm wondering if this script will ever work as is, since it seems like it will always exit before it completes its 'mission'. Perhaps you could change that subroutine to by deleting the exit() statements or changing exit(0); to return;.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|