/**
 * Connects to a Telnet server, uses su command to change to root and changes the password for a specified account.
 * 
 * The account and new password are aquired using the prompt command, prompting the user for these values
 * and storing in variables named "account" and "newpass" respectively.
 * 
 * Expected prompts for changing the account password are defined in the "newpasswordprompt" and 
 * "retypepasswordprompt" variables defined below.  These must match your system prompts. Account information used to 
 * login is specified in the "username" and "password" variables.  Root password is stored in "rootpassword" variable.
 */


// VARIABLES 

// hostname of telnet server
prompt hostname "Enter hostname: "

// username to login with
prompt username "Enter non-root username to login as: "

// password to login with
prompt password "Enter password for this user: "

// default shell prompt expected after login
set shellprompt "$"

// login prompt expected
set loginprompt "login:"

// password prompt expected
set passwordprompt "Password:"

// root account shell prompt
set rootshellprompt "#"

// root account password .. needed for su command
prompt rootpassword "Enter root password: "

// prompt for sending new password
set newpasswordprompt "New UNIX password:"

// prompt for retyping new password
set retypepasswordprompt "Retype new UNIX password:"

// SCRIPT EXECUTION

// prompt user for the username to change password for and store as account variable
prompt account "Enter the username to change password for: "

// prompt user for the new password for this acocunt and store as newpass variable
prompt newpass "Enter the new password for this account: "

// status message
msg "Establishing a connection.  Please wait..."

// establish a connection
connect

// su to root account
sendwait "su" "Password:"

// send password of root account and wait for root prompt
sendwait "${rootpassword}" "${rootshellprompt}"

// request change password of user and wait for prompt
sendwait "passwd ${account}" "${newpasswordprompt}"

// send new password for user and wait for prompt
sendwait "${newpass}" "${retypepasswordprompt}"

// retype new password for user and wait for root prompt
sendwait "${newpass}" "${rootshellprompt}"

// exit out of root shell and wait for default shell prompt
sendwait "exit" "${shellprompt}"

// exit out of default shell ... do not wait for prompt
sendnowait "exit"

// wait 3 seconds and then disconnect
wait 3

// disconnect
disconnect

// status message
msg "\r\nFinished.  Password update complete."
