in reply to Re: Changing passwords using Expect.pm through ssh on a large number (75) of systems
in thread Changing passwords using Expect.pm through ssh on a large number (75) of systems
#!/usr/bin/perl -w use strict; use Expect; my $timeout = '5'; my $username = 'luser'; my $newpass = 'luser'; my $oldpass = 'n3wp@ss!'; open(HOSTS,"hosts.txt") or die "Error while opening file:$!\n"; chomp( my @hosts = <HOSTS> ); close(HOSTS) or die "Error while closing file:$!\n"; my $exp; foreach (@hosts) { $exp = Expect->spawn("ssh -l $username $_") or die "Cannot spawn ssh: $!\n";; my $spawn_ok; #$exp->exp_internal(1); do_exp ($timeout, 'password', $oldpass); do_exp ($timeout, "$username\n", "passwd"); do_exp ($timeout, 'password:', $oldpass); do_exp ($timeout, 'password:', $newpass); do_exp ($timeout, 'password:', $newpass); } sub do_exp { my ($_timeout, $_lookfor, $_send) = @_; if ($exp->expect($_timeout,'-re',$_lookfor)) { $exp->send($_send); } else { die "Timeout waiting for $_lookfor.\n"; } }
Starting EXPECT pattern matching... Expect::expect('Expect=GLOB(0x835f7e0)', 5, '-re', 'password') cal +led at ./example.pl line 30 main::do_exp(5, 'password', 'n3wp@ss!') called at ./example.pl lin +e 21 spawn id(3): list of patterns: #1: -re `password' spawn id(3): Does `' match: pattern #1: -re `password'? No. luser@10.10.10.39's password: spawn id(3): Does `luser@10.10.10.39\'s password: ' match: pattern #1: -re `password'? YES!! Before match string: `luser@10.10.10.39\'s ' Match string: `password' After match string: `: ' Matchlist: () Sending 'n3wp@ss!' to spawn id(3) Expect::print('Expect=GLOB(0x835f7e0)', 'n3wp@ss!') called at ./ex +ample.pl line 30 main::do_exp(5, 'password', 'n3wp@ss!') called at ./example.pl lin +e 21 Starting EXPECT pattern matching... Expect::expect('Expect=GLOB(0x835f7e0)', 5, '-re', 'luser^J') call +ed at ./example.pl line 30 main::do_exp(5, 'luser^J', 'passwd') called at ./example.pl line 2 +2 spawn id(3): list of patterns: #1: -re `luser\n' spawn id(3): Does `: ' match: pattern #1: -re `luser\n'? No. n3wp@ss! spawn id(3): Does `: n3wp@ss!' match: pattern #1: -re `luser\n'? No. Timeout waiting for luser
Thanks again for the assist!luser@10.10.10.39's password: n3wp@ss!Timeout waiting for luser .
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Changing passwords using Expect.pm through ssh on a large number (75) of systems
by sschneid (Deacon) on Jul 11, 2002 at 22:55 UTC | |
by linebacker (Scribe) on Jul 12, 2002 at 02:36 UTC |