#!/usr/bin/perl
# non interactive password
use Expect;

$user=@ARGV[0];
#print $user."\n";
$pass=@ARGV[1];

chomp($pass);
# print $pass;
 
$command = Expect->spawn("/usr/bin/passwd $user")
        or die "Couldn't start the program";

# prevent the program's output from being shown on our STDOUT
$command->log_stdout(1);

# wait 10 seconds for "Password:" to appear
$command->expect(10,'-re','word:\s$' )
        or die "Spawn Timed Out";

# Password
print $command "$pass\r";

# wait 10 seconds for "Password:" to appear
$command->expect(10,'-re','word:\s$' )
        or die "Password Timed Out";

# Password
print $command "$pass\r";

# send exit
print $command "exit\r";

# if the program will terminate by itself, finish up with
$command->soft_close();

exit 0;
