From: MAGANA, A. S I C. U. A. 72 ABW/S. <and...@us...> - 2015-03-26 19:09:05
Attachments:
smime.p7s
|
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. //SIGNED// Andy Magaña UNIX Systems Administrator Diligent Contractor, 72nd Air Base Wing Tinker Air Force Base, Oklahoma Commercial: (405) 734-0341 |
From: MAGANA, A. S I C. U. A. 72 ABW/S. <and...@us...> - 2015-03-26 19:45:24
Attachments:
smime.p7s
|
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. #!/usr/bin/perl use strict; use Expect; my $ssh = Expect->new('ssh user@host'); #$ssh->debug(1); $ssh->expect(5, q{Password:}); $ssh->send("password\n"); $ssh->expect(5, '$'); #$ssh->send("exit\n"); #$ssh->close(); exp_continue; //SIGNED// Andy Magaña UNIX Systems Administrator Diligent Contractor, 72nd Air Base Wing Tinker Air Force Base, Oklahoma Commercial: (405) 734-0341 |
From: Matt Z. <mzagrabe@d.umn.edu> - 2015-03-26 20:03:58
|
On Thu, Mar 26, 2015 at 2:12 PM, MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT <and...@us...> wrote: > 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. > > #!/usr/bin/perl > use strict; > use Expect; > > my $ssh = Expect->new('ssh user@host'); > #$ssh->debug(1); > $ssh->expect(5, q{Password:}); > $ssh->send("password\n"); > $ssh->expect(5, '$'); > #$ssh->send("exit\n"); > #$ssh->close(); > exp_continue; and what is the output? -m |
From: MAGANA, A. S I C. U. A. 72 ABW/S. <and...@us...> - 2015-03-26 20:34:53
|
$ Closing spawn id(3). at /usr/lib/perl5/site_perl/5.8.8/Expect.pm line 1431 Expect::hard_close('Expect=GLOB(0xd552470)') called at /usr/lib/perl5/site_perl/5.8.8/Expect.pm line 1621 Expect::DESTROY('Expect=GLOB(0xd552470)') called at tester-b line 0 eval {...} called at tester-b line 0 spawn id(3) closed. Pid 32508 of spawn id(3) terminated, Status: 0xFF00 //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: Matt Zagrabelny [mailto:mzagrabe@d.umn.edu] Sent: Thursday, March 26, 2015 3:04 PM To: MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT Cc: exp...@li... Subject: Re: [Expectperl-discuss] expect.pm script On Thu, Mar 26, 2015 at 2:12 PM, MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT <and...@us...> wrote: > 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. > > #!/usr/bin/perl > use strict; > use Expect; > > my $ssh = Expect->new('ssh user@host'); #$ssh->debug(1); > $ssh->expect(5, q{Password:}); $ssh->send("password\n"); > $ssh->expect(5, '$'); #$ssh->send("exit\n"); #$ssh->close(); > exp_continue; and what is the output? -m |
From: Matt Z. <mzagrabe@d.umn.edu> - 2015-03-26 20:47:52
|
On Thu, Mar 26, 2015 at 3:13 PM, MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT <and...@us...> wrote: > $ Closing spawn id(3). > at /usr/lib/perl5/site_perl/5.8.8/Expect.pm line 1431 > Expect::hard_close('Expect=GLOB(0xd552470)') called at /usr/lib/perl5/site_perl/5.8.8/Expect.pm line 1621 > Expect::DESTROY('Expect=GLOB(0xd552470)') called at tester-b line 0 > eval {...} called at tester-b line 0 > spawn id(3) closed. > Pid 32508 of spawn id(3) terminated, Status: 0xFF00 Hi Andy, Sorry I don't have the time (or expertise) to go through your error messages - it's been ages since I've used expect and was mostly a novice when I was using it. Here is a snippet that I dredged up and verified that it ssh'ed. Please forgive the rough spots of the following code - it is many years old and I'm only posting it here as evidence that ssh'ing can be done. :) #!/usr/bin/perl use strict; use warnings; use Expect; my $debug = 0; my $TIMEOUT = 5; my $command = '/usr/bin/ssh user@host'; my $exp = Expect->spawn($command) or die "Cannot spawn $command: $!\n"; wait_for_and_send('Password:', "supersecretpassword\n", $exp); # I use the % sign in my prompt. You can change it to a $. wait_for_and_send('%', "date\n", $exp); sub wait_for_and_send { my $wait_for = shift; my $send = shift; my $exp = shift; if (&wait($wait_for, $exp)) { print "\nsending '$send'\n" if ($debug); $exp->send($send); return 1; } else { print "Did not wait.\n"; return undef; } } sub wait { my $prompt = shift; my $exp = shift; if ($exp->expect($TIMEOUT, $prompt)) { print "\nfound '$prompt'\n" if ($debug); return 1; } else { $exp->hard_close(); print STDERR "Timed out looking for prompt: '$prompt'\n"; return undef; } } -m |
From: MAGANA, A. S I C. U. A. 72 ABW/S. <and...@us...> - 2015-03-26 20:35:15
Attachments:
smime.p7s
|
I have debugging set to $ssh->debug(1) also I am pointing this script to execute on a solaris 10 server. Below are my results. $ Closing spawn id(3). at /usr/lib/perl5/site_perl/5.8.8/Expect.pm line 1431 Expect::hard_close('Expect=GLOB(0xd552470)') called at /usr/lib/perl5/site_perl/5.8.8/Expect.pm line 1621 Expect::DESTROY('Expect=GLOB(0xd552470)') called at tester-b line 0 eval {...} called at tester-b line 0 spawn id(3) closed. Pid 32508 of spawn id(3) terminated, Status: 0xFF00 //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: Matt Zagrabelny [mailto:mzagrabe@d.umn.edu] Sent: Thursday, March 26, 2015 3:04 PM To: MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT Cc: exp...@li... Subject: Re: [Expectperl-discuss] expect.pm script On Thu, Mar 26, 2015 at 2:12 PM, MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT <and...@us...> wrote: > 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. > > #!/usr/bin/perl > use strict; > use Expect; > > my $ssh = Expect->new('ssh user@host'); #$ssh->debug(1); > $ssh->expect(5, q{Password:}); $ssh->send("password\n"); > $ssh->expect(5, '$'); #$ssh->send("exit\n"); #$ssh->close(); > exp_continue; and what is the output? -m |
From: Matt Z. <mzagrabe@d.umn.edu> - 2015-03-26 19:50:39
|
On Thu, Mar 26, 2015 at 2:08 PM, MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT <and...@us...> wrote: > 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. Hi Andy, There are some examples of perl expect out on the net. Try one of those then ask followup questions. If I were you, I'd be looking at a different solution than perl expect to changing passwords on Solaris systems. Cheers! -m |
From: MAGANA, A. S I C. U. A. 72 ABW/S. <and...@us...> - 2015-03-26 19:28:20
Attachments:
smime.p7s
|
I agree. But this is only for temporary time. Thanks. //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: Matt Zagrabelny [mailto:mzagrabe@d.umn.edu] Sent: Thursday, March 26, 2015 2:24 PM To: MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT Cc: exp...@li... Subject: Re: [Expectperl-discuss] expect.pm script On Thu, Mar 26, 2015 at 2:08 PM, MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT <and...@us...> wrote: > 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. Hi Andy, There are some examples of perl expect out on the net. Try one of those then ask followup questions. If I were you, I'd be looking at a different solution than perl expect to changing passwords on Solaris systems. Cheers! -m |
From: Salvador F. <sfa...@ya...> - 2015-03-27 06:36:57
|
----- 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 |
From: MAGANA, A. S I C. U. A. 72 ABW/S. <and...@us...> - 2015-03-27 14:38:13
Attachments:
smime.p7s
|
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 |
From: MAGANA, A. S I C. U. A. 72 ABW/S. <and...@us...> - 2015-03-27 14:38:28
Attachments:
smime.p7s
|
Salvador, 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 |
From: Salvador F. <sfa...@ya...> - 2015-03-27 15:01:51
|
----- Original Message ----- > From: "MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT" <and...@us...> > To: Salvador Fandino <sfa...@ya...>; "exp...@li..." <exp...@li...> > Cc: > Sent: Friday, March 27, 2015 3:38 PM > Subject: RE: [Expectperl-discuss] expect.pm script > > Salvador, > > This change_passwd.pl script looks like what I need can you help me modify it to > be a usable script? You may nned to change the regular expresions passed to the answer_passwd sub to match the prompt used in the target systems. Otherwise, the script works as is. |
From: MAGANA, A. S I C. U. A. 72 ABW/S. <and...@us...> - 2015-03-27 15:17:09
|
Salvador, I looked at the parallel script and where would I put the old and new passwords? Thanks, ReadMode 2, $tty; print $tty "Old password: "; my $old = ReadLine 0, $tty; print $tty "\nNew password: "; my $new = ReadLine 0, $tty; print $tty "\nRetype new password: "; my $new_bis = ReadLine 0, $tty; print $tty "\n"; ReadMode 0, $tty; //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 9:59 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: Salvador Fandino <sfa...@ya...>; > "exp...@li..." > <exp...@li...> > Cc: > Sent: Friday, March 27, 2015 3:38 PM > Subject: RE: [Expectperl-discuss] expect.pm script > > Salvador, > > This change_passwd.pl script looks like what I need can you help me > modify it to be a usable script? You may nned to change the regular expresions passed to the answer_passwd sub to match the prompt used in the target systems. Otherwise, the script works as is. |
From: Salvador F. <sfa...@ya...> - 2015-03-27 15:31:59
|
----- Original Message ----- > From: "MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT" <and...@us...> > To: Salvador Fandino <sfa...@ya...>; "exp...@li..." <exp...@li...> > Cc: > Sent: Friday, March 27, 2015 4:16 PM > Subject: RE: [Expectperl-discuss] expect.pm script > > Salvador, > > I looked at the parallel script and where would I put the old and new passwords? in $old and $new? |
From: MAGANA, A. S I C. U. A. 72 ABW/S. <and...@us...> - 2015-03-27 18:57:30
Attachments:
smime.p7s
|
just to be sure I would replace the ReadLine 0 with mysecretpassword my $old = ReadLine 0, $tty; print $tty "\nNew password: "; my $new = ReadLine 0, $tty; print $tty "\nRetype new password: "; my $new_bis = ReadLine 0, $tty; print $tty "\n"; ReadMode 0, $tty; //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 10:29 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: Salvador Fandino <sfa...@ya...>; "exp...@li..." <exp...@li...> > Cc: > Sent: Friday, March 27, 2015 4:16 PM > Subject: RE: [Expectperl-discuss] expect.pm script > > Salvador, > > I looked at the parallel script and where would I put the old and new passwords? in $old and $new? |
From: MAGANA, A. S I C. U. A. 72 ABW/S. <and...@us...> - 2015-03-27 15:25:46
Attachments:
smime.p7s
|
How can I stick a user into the script like me amagana into the script? //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 9:59 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: Salvador Fandino <sfa...@ya...>; > "exp...@li..." > <exp...@li...> > Cc: > Sent: Friday, March 27, 2015 3:38 PM > Subject: RE: [Expectperl-discuss] expect.pm script > > Salvador, > > This change_passwd.pl script looks like what I need can you help me > modify it to be a usable script? You may nned to change the regular expresions passed to the answer_passwd sub to match the prompt used in the target systems. Otherwise, the script works as is. |
From: MAGANA, A. S I C. U. A. 72 ABW/S. <and...@us...> - 2015-03-27 21:49:26
Attachments:
smime.p7s
|
I ran this script "parallel_passwd.pl" from a linux box and I wanted to change my password on a solaris 10 server but after I enter the old password and new password I get nothing back, not even a timeout or error. I run the perl script like this: perl ./parallel_passwd.pl -l myloginname remoteserver //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 9:59 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: Salvador Fandino <sfa...@ya...>; > "exp...@li..." > <exp...@li...> > Cc: > Sent: Friday, March 27, 2015 3:38 PM > Subject: RE: [Expectperl-discuss] expect.pm script > > Salvador, > > This change_passwd.pl script looks like what I need can you help me > modify it to be a usable script? You may nned to change the regular expresions passed to the answer_passwd sub to match the prompt used in the target systems. Otherwise, the script works as is. |