Shell Change Password to original password

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.