From: Matt Z. <mzagrabe@d.umn.edu> - 2015-03-31 20:55:57
|
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(); } |