午夜国产狂喷潮在线观看|国产AⅤ精品一区二区久久|中文字幕AV中文字幕|国产看片高清在线

    expect實(shí)現(xiàn)批量修改linux密碼腳本分享
    來源:易賢網(wǎng) 閱讀:1634 次 日期:2015-01-30 14:51:11
    溫馨提示:易賢網(wǎng)小編為您整理了“expect實(shí)現(xiàn)批量修改linux密碼腳本分享”,方便廣大網(wǎng)友查閱!

    最近對(duì)linux批量執(zhí)行的腳本很感興趣,在網(wǎng)上到處找有關(guān)expect批量執(zhí)行腳本,今天就給大家共享一個(gè)批量修改密碼的腳本.

    腳本內(nèi)容:

    代碼如下:

    #!/usr/bin/expect

    if { $argc<2 } {

    send_user "usage: $argv0 <host file> <cmd file> \n"

    exit

    }

    # 機(jī)器列表數(shù)據(jù)格式: IP 端口 舊密碼 新密碼

    set hostfile [ open [lindex $argv 0] ]

    # 命令列表數(shù)據(jù)格式: 一條命令一行

    set cmdfile [ open [lindex $argv 1] ]

    # 數(shù)據(jù)文件分割符,默認(rèn)為空格

    set part "\ "

    # 過濾關(guān)鍵字

    set key_password "password:\ "

    set key_init "\(yes/no\)\?\ "

    set key_confirm "'yes'\ or\ 'no':\ "

    set key_ps "*]#\ "

    set key_newpassword "UNIX password:\ "

    set timeout 30

    log_file ./exprct.log

    match_max 20480

    while {[gets $hostfile _hosts_] >= 0} {

    set hosts [string trim $_hosts_]

    set str_index [string first $part $hosts]

    set host [string trim [string range $hosts 0 $str_index]]

    set temp [string trim [string range $hosts [expr $str_index + 1] [string length $hosts]]]

    set str_index [string first $part $temp]

    if { $str_index == -1 } {

    set port 22

    set pass $temp

    set newpass $temp

    } else {

    set port [string trim [string range $temp 0 $str_index]]

    set temp_pass [string trim [string range $temp [expr $str_index + 1] [string length $temp]]]

    set str_index [string first $part $temp_pass]

    set pass [string trim [string range $temp_pass 0 $str_index]]

    set newpass [string trim [string range $temp_pass [expr $str_index + 1] [string length $temp_pass]]]

    }

    spawn ssh -p $port $host

    while {1} {

    expect {

    "$key_password" {

    send "$pass\r"

    }

    "$key_init" {

    send "yes\r"

    }

    "$key_confirm" {

    send "yes\r"

    }

    "$key_ps" {

    while {[gets $cmdfile cmd] >= 0} {

    send "$cmd\r"

    expect {

    "$key_ps" {

    continue

    }

    "$key_newpassword" {

    send "$newpass\r"

    expect "$key_newpassword" {

    send "$newpass\r"

    expect "$key_ps"

    continue

    }

    }

    }

    }

    seek $cmdfile 0 start

    send_user "\r"

    break

    }

    timeout {

    puts "$host timeout\n"

    break

    }

    }

    }

    send "exit\r"

    close

    wait

    }

    close $hostfile

    close $cmdfile

    exit

    更多信息請(qǐng)查看IT技術(shù)專欄

    更多信息請(qǐng)查看腳本欄目
    易賢網(wǎng)手機(jī)網(wǎng)站地址:expect實(shí)現(xiàn)批量修改linux密碼腳本分享
    由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

    2025國(guó)考·省考課程試聽報(bào)名

    • 報(bào)班類型
    • 姓名
    • 手機(jī)號(hào)
    • 驗(yàn)證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn) | 投訴建議
    工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
    云南網(wǎng)警備案專用圖標(biāo)
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
    云南網(wǎng)警報(bào)警專用圖標(biāo)