我有一个文件,有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