You are getting the error because there is no semicolon at the end of the line
my $my_header = $header
That line should be in the change_password subroutine with the other ones I gave you. That subroutine should be:
sub change_password {
my $system = shift;
my $ssh = Expect->new('ssh amagana@' . $system);
$ssh->debug(1);
$ssh->log_file("$filename");
my $my_header = $header; ###### This line added <<<<
$my_header =~ s/system/$system/;
$ssh->print_log_file($header);
$ssh->expect ( $timeout,
[ qr/Password:/],
[ qr/Are you sure you want to continue connecting \(yes\/no\)?/]
);
if ($ssh->match() =~ m/Are you sure you want to continue connecting \(
+yes\/no\)?
+/ ) {
$ssh->send("yes\r");
}
elsif ($ssh->match() =~ m/Password:/ ) {
$ssh->send("mycurrentpassword\n");
}
$ssh->expect(60, '$');
$ssh->send("su - root\n");
$ssh->expect(60, 'Password:');
$ssh->send("rootpassword\n");
$ssh->expect(60, '#');
$ssh->send("hostname\n");
$ssh->expect(60, '#');
$ssh->send("uptime\n");
$ssh->expect(60, '#');
$ssh->send("passwd amagana\n");
$ssh->expect(60, 'New Password:');
$ssh->send("mynewpassword\n");
$ssh->expect(60, 'Re-enter new Password:');
$ssh->send("mynewpassword\n");
$ssh->expect(60, '#');
$ssh->send("exit\n");
$ssh->expect(60, '$');
$ssh->send("exit\n");
$ssh->close();
}
The idea is to make a local copy of the header in the subroutine, then change "system" to the actual system name. This way the original header text is unchanged and will be available for subsequent calls.
-
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.