我有一個文件,有IP地址,文件和密碼的位置。我無法使用ssh密鑰驗證,這就是爲什麼我僅限於在bash腳本中使用expect。該文件包含的信息如下,用空格分隔:希望SSH無密碼
IP位置密碼
IP位置密碼
等
我的腳本是:
VAR=$(expect -c "
set fid [open "file.conf" w]
set content [read $fid]
close $fid
set records [split $content "\n"]
foreach rec $records {
set fields [split $rec]
lassign $fields\ ip location password
puts "$ip"
puts "$location"
puts "$password"}
spawn ssh $ip tail -f $location > /home/log_$ip 2>/dev/null &
expect {
".*Are.*.*yes.*no.*" { send "yes\n" }
"*?assword:*" { send "$password\r" }
}
")
回聲「$ VAR 「
當我運行腳本時,它給我是錯誤:
錯誤#參數:應該是「讀取channelId?numChars?」或在執行 「讀?-nonewline?渠道ID」 「讀」 從 中調用「設置內容[閱讀]」
可以請人幫我做尾巴-f在後臺運行 – user2864207