linuxexpect執行腳本
expect -c 用全路徑?比如 /usr/bin/expect -c
㈡ Linux操作系統中expect如何使用
在Linux系統中,expect是一個自動化交互套件,也是一個用來處理交互的命令;利用expect,我們可以將交互過程寫在一個腳本上,讓其自動化完成,從而幫助運維人員提高工作效率、節約時間。那麼Linux系統中expect該如何使用?我們來看看詳細的內容介紹。
Linux系統中expect該如何使用?
expect是一個自動化交互套件,主要應用於執行命令和程序時,系統以交互形式要求輸入指定字元串,實現交互通信。
expect自動交互流程:
spawn啟動指定進程--expect獲取指定關鍵字--send向指定程序發送指定字元--執行完成退出。
注意:該腳本能夠執行的前提條件是安裝了expect
yum install -y expect
expect常用命令總結:
spawn 交互程序開始後面跟命令或者指定程序;
expect 獲取匹配信息匹配成功則執行expect後面的程序動作;
send exp_send 用於發送指定的字元串信息;
exp_continue 在expect中多次匹配就需要用到;
exit 退出expect腳本;
eof expect 執行結束 退出;
set 定義變數;
puts 輸出變數;
set timeout 設置超時時間。
㈢ linux:關於expect腳本,為什麼這么寫不對呢求解
mkdir又不是expect的命令。
#!/usr/local/bin/expect
spawnsu-root
expect"Password:"
send"123456 "
sleep3
send"mkdir/usr/local/ddddd "
㈣ 用expect實現telnet登陸到linux系統後,再執行一個shell腳本,待這個shell腳
參考一種類自然語言的腳本語言:
001 var {v_time} value datetime
002 screen.text at point {10} {30} string {2. telnet ipv4 (192.168.186.132:23) test , datetime: ~v_time~}
003
004 telnet.connect ip {192.168.186.132} port {23}
005 telnet.recv expect {Username:}
006 telnet.send {cisco%0a}
007 telnet.recv expect {Password}
008
009 telnet.send {cisco%0a}
010 telnet.recv expect {>}
011 telnet.send {enable%0a}
012 telnet.set onrecv {More} send { }
013 telnet.set delay {200} ms after per byte send
014 telnet.send {show version%0a}
015 telnet.recv for {5} seconds
016
017 telnet.send {show run%0a}
018 telnet.recv for {5} seconds
019 telnet.send {exit%0a}
020 telnet.close
021
022 var {v_time} value datetime
023 screen.text at point {10} {60} string {telnet tested end. datetime:~v_time~}
024
025 run.end

--------------------------------------------------------------------
簡單網路管理語言(Simple Network Management Language)是一種類自然語言的腳本語言,它採用snmp、telnet、ping、dns、arp、ssh、tcp、udp、web等協議訪問網路設備,內置smtp協議用於告警等郵件的發送,支持excel、mysql、sqlite等3種方式進行網管數據的存取。
最新版本: snml8.13(ladybird20200205) utf8&ipv6
項目託管地址:https://github.com/ladybirdSnml/snmlipv6utf8snmptelnetsshweb
打包下載:https://ladybirdsnml.github.io/snmlipv6utf8snmptelnetsshweb/snml_utf8ipv6.zip
㈤ linux expect講解怎麼使用
[root@zuozhang PYTHON_TEST]# rpm -ql expect package expect is not installed 查看是否有安裝,如果沒有安裝安裝一個即可。 yum install expect*
㈥ Linux自動登陸expect 遠程主機執行本地腳本
兩台ssh之間做個密鑰,盡量不要使用expect寫腳本。因為expect互動式登錄是需要你在腳本中寫密碼的。
㈦ linux下expect腳本問題
#!/usr/bin/expect-f
if{$argc!=1}{
puts"usage:$argv0IP"
exit1
}else{
setIP[lindex$argv0]
}
setpingcmd[format"ping-c100%s"$IP]
settimeout6000
#比如遠程用戶叫做test
setdestusertest
#比如遠程伺服器IP為如下
setdestip192.168.0.123
setdestpath"$destuser@$destip"
#比如用戶密碼叫做test
setdestpasswordtest
#ssh登錄
spawnssh$destpath
#######################
expect{
-re".*yes/no.*"{
exp_send"yes "
exp_continue
}
-re".*assword.*"{
exp_send"$destpassword "
}
}
#比如ssh登錄以後的提示符是test@Testserver>
expect{
-re".*test@Testserver.*"{
exp_send"$pingcmd "
}
}
expect{
#如果輸出timeout字元,則Control+C結束pingcmd
#這里用的是DestinationHostUnreachabl替換timeout。因為本人機器上沒有timeout.
-re".*DestinationHostUnreachabl.*"{
#輸入Control+c
exp_send"
