Linux零碎知識 expect

2021-10-10 20:37:46 字數 1112 閱讀 6687

expect命令簡單介紹就是,它可以模擬鍵盤輸入文字,它是乙個自動化互動套件,主要用在執行命令或者程式需要輸入密碼或者其它文字是,可以自動輸入,不至於讓終端處於阻塞態

expect的用法,網上搜搜有很多,這裡給出兩個鏈結

linux expect詳解

指令碼ssh連線自動填密碼(expect)

這兩個鏈結裡都給了詳細的例子,但是我在使用的時候,發現了乙個需要注意的地方,也是容易出錯的地方

#! /bin/bash

expect -c "

set timeout 1;

spawn ssh [email protected] -p 22 ;

expect

*password*

} ;expect test2@* ;

expect test2@* ;

expect eof ;

"

#! /bin/bash

/usr/bin/expect <<-eof

settimeout 1

spawn ssh [email protected] -p 22

expect

"*password*"

}expect

"*test2@*"

send "ls\r"

send "exit\r"

expect eof

eof

上面給出了兩個例子,實現的功能也完全一模一樣,即,通過shell呼叫expect,那我們來分析一下,這兩種寫法的區別在哪

1、對於expect的呼叫方式不一樣,也就是指令碼主體內容第一行

首先是 expect -c 這種寫法的意思是,整個引號中的內容為字串,也就相當於指令碼內容

而/usr/bin/expect <<-eof 這種寫法的意思是,兩個eof之間的內容就是待執行的指令碼

2、因為上述區別,導致了乙個細微的區別,就是send命令後面,引號的使用,乙個需要\"做轉義,另乙個不需要,這個也是非常容易弄糊塗的地方!!

路漫漫其修遠兮,吾將上下而求索

零碎知識C

c 中 dec,hex,oct,fixed,scientific,left,right,ws,setfill,setw,setprecision,eof,get,getline都是什麼意思 dec是十進位制 如cout這些是格式控制符 在使用時要加標頭檔案 include fixed是固定的意思 p...

JavaBean零碎知識

上面等價於下列操作 1.從scope session 中獲取id customer 屬性值,賦值給class com.stuipid.bean.customer 型別的id customer 變數 customer customer customer session.getattribute cus...

零碎知識點

1.反斜槓也可拼接字串 window.nl ad function window.nl ad function 2.在console.log 中新增樣式 var a hello console.log c a,font size 400 background blue color white 3 通...