[ale] Modifying Password from USERMOD command!

Mike Fletcher fletch at phydeaux.org
Thu May 27 22:50:18 EDT 1999


>>>>> "Bhaskar" == Bhaskar Kumar Regmi <bhaskar at ait.ac.th> writes:

    Bhaskar> Using USERADD or USERMOD without a password works fine,
    Bhaskar> but my point is with -p option also it should work. For
    Bhaskar> one/two users its okey, i can change password using
    Bhaskar> PASSWD command. But when creating 200/300 users it's
    Bhaskar> really boring to type password and conform it again.

	This is where something like the tcl expect extension or the
perl Expect module comes in real handy:

--------------------------------------------------
#!/usr/bin/perl
use strict;

die "Must run as root to set passwords.\n" unless $> == 0;

use Expect ();

system( qw(stty -echo) );

open( TTY, '/dev/tty' ) or die "Can't open tty: $!\n";

print "Password: ";

chomp( my $pass = <TTY> );
system( qw(stty echo) );

print "\n";

for( <> ) {
  my $p = Expect->spawn( 'passwd', $_ );

  my $ret = $p->expect( 10, "word:" );
  die "passwd timed out!\n" if $ret eq '1:TIMEOUT';

  print $p "$pass\r";   

  $ret = $p->expect( 10, "word:" );
  die "passwd timed out!\n" if $ret eq '1:TIMEOUT';

  print $p "$pass\r";

  $p->close();
}

exit 0;
--------------------------------------------------

	expect comes with (or used to come with) a similar `passmass'
script.

-- 
Fletch                |                                            __`'/|
fletch at phydeaux.org   |       "I drank what?" -- Socrates          \ o.O'
678 443-6239(w)       |                                            =(___)=
                      |                                               U






More information about the Ale mailing list