expect 指令碼中可實現非互動式操作

2021-08-21 22:01:47 字數 666 閱讀 8510

如何用expect自動幫你發郵件(自動互動)

[root@localhost ~]# mail -s ddd root

vim sss.sh

#! /bin/bash

expect <[root@server0 ~]# mail -s test root << eof  寫郵件

> test mail

> hell world

> eof

通過迴圈批量操作,版本2:

[root@svr5 ~]# vim  expect_ssh.sh

#!/bin/bash

for i in 10 11

doexpect << eof

spawn ssh 172.25.0.$i                               #//建立互動式程序

expect "password:"              #//自動傳送密碼

expect "#         #//傳送命令

expect "#" 

eofdone

注意事項:

expect指令碼的最後一行預設不執行

如果不希望ssh時出現yes/no的提示,遠端時使用如下選項:

# ssh -o stricthostkeychecking=no server0

expect 自動互動指令碼

命令列引數 ar 引數陣列,使用 lindex ar n 獲取,ar 0為指令碼名字 argc,引數個數 set username lindex ar 1 獲取第1個引數 set passwd lindex ar 2 獲取第2個引數 set timeout 30 設定超時 spawn是expect內...

使用expect指令碼實現linux的互動式操作

root localhost tar zxvf tcl8.6.8 src.tar.gz root localhost cd tcl8.6.8 unix root localhost configure prefix usr tcl enable shared root localhost make ...

EXPECT 指令碼 批量 遠端互動

在shell自動部署專案中對自動部署免去使用者互動很痛苦 expect eof 這個一定要加,與spawn對應表示捕獲終端輸出資訊終止,類似於if.endif expect指令碼必須以interact或expect eof結束,執行自動化任務通常expect eof就夠了。設定expect永不超時。...