以下expect脚本将删除远程计算机上的文件/ var / tmp / file
但在此之前,expect脚本在远程计算机上执行ssh,
我放2>/tmp/errors
以便从ssh
但我注意到尽管ssh远程发送错误,但我没有看到来自/tmp/errors
文件的错误
但是当我尝试手动
时ssh $LOGIN@$machine
然后ssh在WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED
但是我希望我不能在/tmp/erros
请指出什么是错的?为什么2>/tmp/errors
没有捕获错误?
expect_test=`cat << EOF
set timeout 50
spawn ssh $LOGIN@$machine 2>/tmp/errors
expect {
")?" { send "yes\r" ; exp_continue }
word: { sleep 1 ; send $PASSORD\r}
}
expect > {send "sleep 1\r"}
expect > {send "rm -f /var/tmp/file\r"}
expect > {send exit\r}
expect eof
EOF`
expect -c "$expect_remove_file"
答案 0 :(得分:2)
spawn
无法理解I / O重定向。取代
spawn ssh $LOGIN@$machine 2>/tmp/errors
使用
spawn ssh $LOGIN@$machine -E /tmp/errors
# -E log_file tells ssh where to write the error log instead of stderr
或
spawn sh -c "ssh $LOGIN@$machine 2>/tmp/errors"