From: <jfe...@gm...> - 2015-04-01 00:40:01
|
The "\n" is not needed on $ssh->expect("New Password:\n"); you can use $ssh->expect("word"); On Tue, Mar 31, 2015 at 2:18 PM, mike nicholas <xmi...@gm...> wrote: > I like to name my log files with the name or IP used to connect to the > device, makes grepping through them easy to identify where the line came > from. :) > > On Tue, Mar 31, 2015 at 4:15 PM, ESRY JR., DON <de...@at...> wrote: > >> I think you will want a log file to identify where the script failed. >> >> I recommend that you take out the 'w' from the >> $ssh->log_file($filename, 'w'); >> so it will append to the file rather than over writing it for each server. >> >> And then put in some sort of header for each server, something like: >> my $header = "\n\n======= $system =======\n"; >> $ssh->print_log_file($header); >> >> Or if you prefer a separate file for each server, then >> my $filename = "/var/tmp/expect_script_". $system ".log"; >> >> little stuff like this can be very frustrating. >> >> >> -----Original Message----- >> From: Matt Zagrabelny [mailto:mzagrabe@d.umn.edu] >> Sent: Tuesday, March 31, 2015 4:56 PM >> To: MAGANA, ANDREAS S I CTR USAF AFMC 72 ABW/SCOOT >> Cc: exp...@li... >> Subject: Re: [Expectperl-discuss] expect.pm not updating password >> >> On Tue, Mar 31, 2015 at 3:37 PM, MAGANA, ANDREAS S I CTR USAF AFMC 72 >> ABW/SCOOT <and...@us...> wrote: >> > Thank you Matt, >> > >> > I just don't know how to put it in a working way I learn by examples I >> am a >> > novice on perl and the modules. >> >> Maybe spend a day or two writing some basic perl programs so you feel >> more comfortable with this stuff. I'm sure there are truckloads of >> perl tutorials out there. >> >> I added some context below. You'll need to clean up the leading '>' >> characters. >> >> -m >> >> >> > >> > #!/usr/bin/perl >> > use strict; >> > >> > use Expect; >> > >> > # my @servers = qw( >> > # server1.example.net >> > # server2.example.net >> > # server3.example.net >> > # server4.example.net >> > # server5.example.net >> > # ); >> > # >> > # 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->log_file($filename, 'w'); >> > $ssh->expect(60, 'Password:'); >> > $ssh->send("mycurrentpassword\n"); >> > $ssh->expect(60, '$'); >> > $ssh->send("su - root\n"); >> > $ssh->expect(60, 'Password:'); >> > $ssh->send("myrootpassword\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->close(); >> >> } >> >> >> ------------------------------------------------------------------------------ >> Dive into the World of Parallel Programming The Go Parallel Website, >> sponsored >> by Intel and developed in partnership with Slashdot Media, is your hub >> for all >> things parallel software development, from weekly thought leadership >> blogs to >> news, videos, case studies, tutorials and more. Take a look and join the >> conversation now. http://goparallel.sourceforge.net/ >> _______________________________________________ >> Expectperl-discuss mailing list >> Exp...@li... >> https://lists.sourceforge.net/lists/listinfo/expectperl-discuss >> >> >> ------------------------------------------------------------------------------ >> Dive into the World of Parallel Programming The Go Parallel Website, >> sponsored >> by Intel and developed in partnership with Slashdot Media, is your hub >> for all >> things parallel software development, from weekly thought leadership >> blogs to >> news, videos, case studies, tutorials and more. Take a look and join the >> conversation now. http://goparallel.sourceforge.net/ >> _______________________________________________ >> Expectperl-discuss mailing list >> Exp...@li... >> https://lists.sourceforge.net/lists/listinfo/expectperl-discuss >> > > > > ------------------------------------------------------------------------------ > Dive into the World of Parallel Programming The Go Parallel Website, > sponsored > by Intel and developed in partnership with Slashdot Media, is your hub for > all > things parallel software development, from weekly thought leadership blogs > to > news, videos, case studies, tutorials and more. Take a look and join the > conversation now. http://goparallel.sourceforge.net/ > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > > |