#!/usr/bin/expect -f
#
# Author: Chris Narcouzi cnarcouz [ at ] cswg [ dot ] com
#
# This script changes the password of a user without being prompted for
# the passord itself. It is used in conjuction with another ksh script
# called change_passwd.sh that provides the UNIX box name, the userid, and
# the root password. This script sets the user's password to "1234" but
# you can change it to anything you like.
#
proc usage {} {
send_error "usage: change_passwd \n"
exit 1
}
if {[llength $argv] < 2} usage
set hostname [lindex $argv 0]
set userid [lindex $argv 1]
set rootpasswd [lindex $argv 2]
set timeout -1
spawn telnet $hostname
match_max 100000
expect -exact "login: "
send -- "root\r"
expect -exact "root's Password: "
send -- "$rootpasswd\r"
expect -exact "root@$hostname>"
send -- "passwd $userid\r"
expect -exact "New password: "
send -- "1234\r"
expect -exact "new password again:"
send -- "1234\r"
expect -exact "root@$hostname>"
send -- "exit\r"
expect eof