#!/usr/bin/expect -f
# wrapper to make passwd(1) be non-interactive
# username is passed as 1st arg, passwd as 2nd

set password [lindex $argv 1]
spawn /usr/bin/sudo /usr/bin/passwd [lindex $argv 0]
expect "Enter new UNIX password: "
sleep 2
send "$password\r"
expect "Retype new UNIX password: "
sleep 2
send "$password\r"
expect eof