in reply to Shadow Passwords
I would use Expect.pm to communicate with your system's passwd program, which always knows which kind of hash to use, and which may be PAM-enabled to update the password in more places that just /etc/shadow.
Working example code, loosely tested (needs more error checking).
#!/usr/bin/perl -w use strict; use Expect; my @user_pass_pairs = ( [ qw( Tarzan Ungowa ) ], [ qw( Jane GoneNative) ], ); # Time out if we don't get responses within 5 seconds. my $timeout = 5; foreach (@user_pass_pairs) { my ($user, $pass) = @$_; system('useradd', $username) == 0 or die; my $xp = Expect->spawn("passwd $user") or die; $xp->expect($timeout,"New UNIX password: ") or die; print $xp "$pass\r"; $xp->expect($timeout,"Retype new UNIX password: ") or die; print $xp "$pass\r"; $xp->expect( $timeout,"passwd: all authentication tokens updated successfully." ) or die; }
In previous questions, some notable other suggestions were:
Those previous questions were:
|
|---|