#!/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; }