日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux脚本里用expect,如何在bash脚本中使用expect

發(fā)布時間:2023/12/20 linux 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux脚本里用expect,如何在bash脚本中使用expect 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

這是我在

following bash腳本中使用的代碼片段:

for user_input in `awk '{print}' testfile_$$.txt`

do

ipaddress=`echo $user_input | cut -d';' -f 1`

command="${config_mode}`echo $user_input | cut -d';' -f 2-`"

ping -w 1 $ipaddress 1> /dev/null 2> $ERR_LOG_FILE 1> $LOG_FILE

if [ $? -eq 0 ];then

ssh "$USERNAME@$ipaddress" "$command"

>> $LOG_FILE

fi

done

我如何使用expect在此腳本中自動執(zhí)行ssh登錄.

我很期待并開始測試它(它失敗了):

#!/usr/bin/bash

set force_conservative 0 ;# set to 1 to force conservative mode even if

;# script wasn't run conservatively originally

if {$force_conservative} {

set send_slow {1 .1}

proc send {ignore arg} {

sleep .1

exp_send -s -- $arg

}

}

#

set timeout -1

spawn ssh auto21@10.38.227.229 {uname -a; df -h}

match_max 100000

expect "*?assword: "

send -- "bar01\r"

expect eof

我是否需要在expect腳本中重新編寫bash腳本,或者它可以在bash腳本中使用

如果可以的話:

更多我需要獲取bash變量$command,$username,$password,$ipaddress并在期望部分中使用它

你會建議什么解決方案?

要么

我可以創(chuàng)建一個expect腳本并從bash腳本調(diào)用它只是為了登錄,錯誤處理,執(zhí)行,日志文件

總結(jié)

以上是生活随笔為你收集整理的linux脚本里用expect,如何在bash脚本中使用expect的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。