in reply to Re^15: expect.pm header
in thread expect.pm header
My script is going but I do not see that the header changed to the hostname
This is how I inserted the changes into my script
#!/usr/bin/perl -w use warnings; use strict; use Expect; my $filename = "/var/tmp/expect_script.log"; my $timeout = 60; my @servers = qw( remotehost ); for my $server (@servers) { # do your thing with $server change_password($server); } sub change_password { my $system = shift; my $ssh = Expect->new('ssh amagana@' . $system); my $header = "\r\n\r\n======= system =======\r\n"; $ssh->debug(1); $ssh->log_file("$filename"); my $my_header = $header; $ssh->print_log_file($header); $my_header =~ s/system/$system/; $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(); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^17: expect.pm header
by sn1987a (Deacon) on Apr 08, 2015 at 21:20 UTC | |
by amagana (Acolyte) on Apr 08, 2015 at 21:42 UTC | |
by sn1987a (Deacon) on Apr 09, 2015 at 03:25 UTC | |
by amagana (Acolyte) on Apr 10, 2015 at 15:07 UTC | |
by sn1987a (Deacon) on Apr 10, 2015 at 15:39 UTC | |
|
In Section
Seekers of Perl Wisdom