I am needing help with trying to insert a header for each server that gets the password changed in this script.
I think I need a log file to identify where the script failed. But I am not able to get a header as recommended.
I am getting this error:
Global symbol "$system" requires explicit package name at ./tester-a line 7.
Execution of ./tester-a aborted due to compilation errors.
I am trying to insert a header into a log file for each server but I am just not able to get it to work,
#!/usr/bin/perl
use strict;
use Expect;
my $timeout = 60;
my $header = "\n\n======= $system =======\n";
my @servers = qw(
Solaris-host
Solaris-host
Solaris-host
Solaris-host
);
for my $server (@servers) {
# do your thing with $server
change_password($server);
}
sub change_password {
my $system = shift;
my $filename = "/var/tmp/expect_script.log";
my $ssh = Expect->new('ssh amagana@' . $system);
$ssh->debug(1);
$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->print_log_file($header);
$ssh->send("su - root\n");
$ssh->expect(60, 'Password:');
$ssh->send("rootpassword\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->close();
}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.