Shell修改密碼為原密碼

來源:互聯網
上載者:User

標籤:

  密碼到期後更改密碼為原密碼,伺服器多時工作量巨大,編寫指令碼完成。

  登陸後修改提示符為: doraemon# 方便expect匹配

  修改LANG=C,提示為英文防止幹擾:

  

#!/usr/bin/expect################################################################ 串連遠程主機proc do_login {passwd} {    set timeout 10    set done 1    set timeout_case 0    set ps1 {PS1="doraemon#";export PS1}    while {$done<3} {        expect {            *assword* {                send $passwd\r                incr done            }            \[$%>#] {                set done 5                send $ps1\r\r                break            }            timeout {                set done 1                switch -- $timeout_case {                    1 { send_user "try again ...\n" }                    2 { exit 2                        expect eof                    }                }                incr timeout_case            }        }    }    if {$done==3} {        exit 3        expect eof    }}################################################################ 執行命令proc exec_cmd {cmd} {    expect -re "doraemon#$"    send_user "\$cmd: $cmd\n"    send $cmd\r}################################################################ 退出proc logout {} {    expect -re "doraemon#$"    send exit\r    expect eof}################################################################ 執行命令proc change_pass {curr 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:$argv0 user pass ip newpass\n"    exit 1}set user [lindex $argv 0]set pass [lindex $argv 1]set ip [lindex $argv 2]set new [lindex $argv 3]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}spawn ssh -o StrictHostKeyChecking=no -l $user $ip do_login $passexec_cmd "LANG=C;export LANG"exec_cmd passwdchange_pass $pass $pass_1exec_cmd passwdchange_pass $pass_1 $pass_2exec_cmd passwdchange_pass $pass_2 $pass_3exec_cmd passwdchange_pass $pass_3 $pass_4exec_cmd passwdchange_pass $pass_4 $pass_5exec_cmd passwdchange_pass $pass_5 $new    logout

 

Shell修改密碼為原密碼

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.