麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 開發(fā) > Linux Shell > 正文

expect實現(xiàn)批量修改linux密碼腳本分享

2020-07-27 19:09:35
字體:
供稿:網(wǎng)友

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

腳本內(nèi)容:


復(fù)制代碼 代碼如下:

#!/usr/bin/expect
if { $argc<2 } {
    send_user "usage: $argv0 <host file> <cmd file> /n"
    exit
}
 
# 機器列表數(shù)據(jù)格式:  IP  端口  舊密碼  新密碼
set hostfile    [ open [lindex $argv 0] ]
# 命令列表數(shù)據(jù)格式:  一條命令一行
set cmdfile    [ open [lindex $argv 1] ]
 
# 數(shù)據(jù)文件分割符,默認為空格
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

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 久久99国产精品久久99 | 国产精品1区2区 | 欧美一级美国一级 | 成人区一区二区 | 久久人人97超碰国产公开结果 | 激情小说激情图片激情电影 | 日本羞羞的午夜电视剧 | 麻豆蜜桃在线观看 | a视频在线免费观看 | 黄网在线 | sese在线视频 | 久久99精品久久久久久国产越南 | 中文字幕免费播放 | 久久免费激情视频 | 成人在线观看免费观看 | 九九午夜 | 性爱视频免费 | 俄罗斯16一20sex牲色另类 | 高清一区二区在线观看 | 成人福利视频网站 | 视频一区 日韩 | 久久影院免费观看 | 激情视频在线播放 | 成人国产精品齐天大性 | 黄色一级毛片免费看 | 中文字幕亚洲一区二区三区 | 1级黄色毛片 | 久草在线新时代视觉 | 最新欧美精品一区二区三区 | 精品一区二区三区四区在线 | 粉嫩粉嫩一区二区三区在线播放 | 亚洲码无人客一区二区三区 | 国产一区精品在线观看 | 草草久久久 | 色爱99 | 女人叉开腿让男人桶 | 爱福利视频 | 精品国产一区二区三区四 | 在线成人www免费观看视频 | 国产欧美精品一区二区三区四区 | 1314av|