amagana has asked for the wisdom of the Perl Monks concerning the following question:
#!/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(); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: expect.pm header
by roboticus (Chancellor) on Apr 06, 2015 at 20:42 UTC | |
by amagana (Acolyte) on Apr 07, 2015 at 14:08 UTC | |
by GotToBTru (Prior) on Apr 07, 2015 at 15:09 UTC | |
by amagana (Acolyte) on Apr 07, 2015 at 18:14 UTC | |
by sn1987a (Curate) on Apr 07, 2015 at 18:23 UTC | |
| |
|
Re: expect.pm header
by stevieb (Canon) on Apr 06, 2015 at 20:47 UTC | |
by amagana (Acolyte) on Apr 06, 2015 at 21:19 UTC | |
by stevieb (Canon) on Apr 06, 2015 at 21:31 UTC |