#!./expect -f
#
# This program makes passwd(1) non-interactive and sets 
#   the passwd for the user without expecting input from the terminal.
# 
# Usage: setpasswd [user] [password]
#   where,
#      user - User name
#      password - User's new password
#

proc Usage {} {
	send_user "Usage: setpasswd \[user\] \[password\]\n"
	exit 1
}

if {[llength $argv] != 2} { Usage }

set PASSWD [lindex $argv 1]
spawn passwd [lindex $argv 0]
expect -nocase "password:"
send -- "$PASSWD\r"
expect -nocase "password:"
send -- "$PASSWD\r"
expect eof
