<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                [TOC] ## 安裝 `yum install expect -y ` ## 命令 ### spwan 它啟動一個進程,之后所有expect操作都在這個進程中進行 ### expect 等候一個相匹配內容的輸出,一旦匹配則執行expect后面的動作命令, ``` -re 使用正則 expect -re ".*password" {send "root1234\r"} ``` `expect` 就會匹配命令執行后的輸出,然后執行expect后面包含在{}中的send或exp_send動作,匹配及動作可以放在下一行,就可以省略{} 例子 ``` spwan ssh root@192.168.1.26 expect -re ".*password" send "root1234\r" ``` ### 啟用選項 ``` -c 執行腳本前先執行的命令,可多次使用。 -d debug模式,可以在運行時輸出一些診斷信息,與在腳本開始處使用exp_internal 1相似。 -D 啟用交換調式器,可設一整數參數。 -f 從文件讀取命令,僅用于使用#!時。如果文件名為"-",則從stdin讀取(使用"./-"從文件名為-的文件讀取)。 -i 交互式輸入命令,使用"exit"或"EOF"退出輸入狀態。 -- 標示選項結束(如果你需要傳遞與expect選項相似的參數給腳本時),可放到#!行:#!/usr/bin/expect --。 -v 顯示expect版本信息。 ``` ### 命令介紹 ``` close 關閉當前進程的連接。 debug 控制調試器。 disconnect 斷開進程連接(進程仍在后臺運行)。 exit 退出expect。 exp_continue [-continue_timer] 繼續執行下面的匹配。 exp_internal [-f file] value: ``` ## 場景 ### 自動登錄ssh執行命令 ``` #!/usr/bin/expect -f set ip [lindex $argv 0 ] # 接收第1個參數,作為IP set username [lindex $argv 1 ] # 接收第2個參數,作為username set mypassword [lindex $argv 2 ] # 接收第3個參數,作為密碼 set timeout 10 # 設置超時時間 spawn ssh $username@$ip # 發送ssh請求 expect { # 返回信息匹配 "*yes/no" { send "yes\r"; exp_continue} # 第一次ssh連接會提示yes/no,繼續 "*password:" { send "$mypassword\r" } # 出現密碼提示,發送密碼 } interact # 交互模式,用戶會停留在遠程服務器上面 ``` ### 自動建立FTP會話 ``` #!/usr/bin/expect -f set ip [lindex $argv 0 ] # 接收第1個參數,作為IP set userid [lindex $argv 1 ] # 接收第2個參數,作為Userid set mypassword [lindex $argv 2 ] # 接收第3個參數,作為密碼 set timeout 10 # 設置超時時間 # 向遠程服務器請求打開一個FTP會話,并等待服務器詢問用戶名 spawn ftp $ip expect "username:" # 輸入用戶名,并等待服務器詢問密碼 send "$userid\r" expect "password:" # 輸入密碼,并等待FTP提示符的出現 send "$mypassword\r" expect "ftp>" # 切換到二進制模式,并等待FTP提示符的出現 send "bin\r" expect "ftp>" # 關閉ftp的提示符 send "prompt\r" expect "ftp>" # 下載所有文件 send "mget *\r" expect "ftp>" # 退出此次ftp會話,并等待服務器的退出提示EOF send "bye\r" expect eof ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看