After the password expires, change the password to the original password, the server a lot of work, write scripts to complete.
After logging in, modify the prompt to: doraemon# convenient expect match
Modify Lang=c, prompt for English to prevent interference:
#!/usr/bin/expect################################################################ connecting the remote host proc Do_login {passwd} {Set timeoutTenSet Done 1Set Timeout_case0set PS1 {PS1="doraemon#"; export PS1} while{$ Done<3} {expect {*assword*{send $passwd\ r incr Done } \[$%>#] {Set Done 5send $ps 1\r\r break} timeout {set Done 1Switch--$timeout _case {1{Send_user"try again ... \ n" } 2{Exit2expect EOF}} INCR timeout_case} }}if{$ Done==3} {Exit3expect EOF}} ################################################################ Execute command proc exec_cmd {cmd} {expect-re"doraemon#$"Send_user"\ $cmd: $cmd \ n"send $cmd \r}################################################################ exit proc Logout {} {expect-re"doraemon#$"send exit\r expect eof}################################################################ execute command proc Change_pass {C Urr cmd} {expect {-re"current|existing|exist|old| old"{send $curr \ r exp_continue}-re"new|new"{send $cmd \ r exp_continue}-re"successfully|uthentication|changed"{send \ r}}} ###############################################################if{$ARGC <4} {Send_user"Usage: $argv 0 User pass IP newpass\n"Exit1}set User [lindex $argv0]set Pass [lindex $argv1]set IP [lindex $argv2]set New [lindex $argv3]set pass_1 {1pqz!paz}set pass_2 {[email protected]}set pass_3 {3hwd#hwc}set Pass_4 {4zxv$zxv}set pass_5 {5NMB%Nmb}spawnSSH-O Stricthostkeychecking=no-l $user $ip do_login $passexec _cmd"Lang=c;export LANG"Exec_cmdpasswdchange_pass $pass $pass _1exec_cmdpasswdchange_pass $pass _1 $pass _2exec_cmdpasswdchange_pass $pass _2 $pass _3exec_cmdpasswdchange_pass $pass _3 $pass _4exec_cmdpasswdchange_pass $pass _4 $pass _5exec_cmdpasswdchange_pass $pass _5 $new Logout
Shell Change Password to original password