From: MAGANA, A. S I C. U. A. 72 ABW/S. <and...@us...> - 2015-03-27 14:38:13
|
Savador, This change_passwd.pl script looks like what I need can you help me modify it to be a usable script? Thanks, #!/usr/bin/perl use strict; use warnings; use Net::OpenSSH; use Expect; select STDOUT; $| = 1; select STDERR; $| = 1; @ARGV == 3 or die <<USAGE; Usage: $0 host old_password new_password USAGE my ($host, $old, $new) = @ARGV; my $timeout = 20; my $debug = 0; my $ssh = Net::OpenSSH->new($host, password => $old); my ($pty, $pid) = $ssh->open2pty("passwd") or die "open2pty failed: " . $ssh->error . "\n"; my $expect = Expect->init($pty); $expect->raw_pty(1); $debug and $expect->log_user(1); sub answer_passwd { my ($pattern, $pass) = @_; $debug and print "waiting for password prompt\n"; $expect->expect($timeout, -re => $pattern) or die "expect failed\n"; $debug and print "prompt seen\n"; $expect->send("$pass\n"); $debug and print "password sent\n"; $expect->expect($timeout, "\n") or die "bad password\n"; } answer_passwd('current.*:', $old); answer_passwd('new.*:', $new); answer_passwd('new.*:', $new); $expect->expect($timeout, "success") or die "Failed!\n"; print "password updated\n"; //SIGNED// Andy Magaña UNIX Systems Administrator Diligent Contractor, 72nd Air Base Wing Tinker Air Force Base, Oklahoma Commercial: (405) 734-0341 -----Original Message----- From: Salvador Fandino [mailto:sfa...@ya...] Sent: Friday, March 27, 2015 1:34 AM To: MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT; exp...@li... Subject: Re: [Expectperl-discuss] expect.pm script ----- Original Message ----- > From: "MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT" > <and...@us...> > To: "exp...@li..." > <exp...@li...> > Cc: > Sent: Thursday, March 26, 2015 8:08 PM > Subject: [Expectperl-discuss] expect.pm script > > Need help with trying to create a expect.pm script so that I can > change passwords on my Solaris-10 and 9 servers. I am using this > expect.pm script from my Linux server I also have Net::OpenSSH but I am not using right now. > Any examples would help. Net::OpenSSH distribution contains a sample script that does exactly that: https://github.com/salva/p5-Net-OpenSSH/blob/master/sample/change_passwd.pl And then Net::OpenSSH::Parallel distribution contains a similar script that is able to change the password in a bunch of hosts in parallel: https://github.com/salva/p5-Net-OpenSSH-Parallel/blob/master/sample/parallel_passwd.pl |