http://www.perlmonks.org?node_id=1122604

amagana has asked for the wisdom of the Perl Monks concerning the following question:

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(); }