the following expect script will remove the file /var/tmp/file on remote machine
以下expect脚本将删除远程计算机上的文件/ var / tmp / file
but before that the expect script do ssh on the remote machine ,
但在此之前,expect脚本在远程机器上执行ssh,
I put the 2>/tmp/errors
in order to catch error from ssh
我把2> / tmp /错误放到了ssh中来捕获错误
but I notice that in spite ssh to remote send error , I not see the errors from /tmp/errors
file
但我注意到,尽管ssh远程发送错误,我没有看到/ tmp / errors文件中的错误
but when I tryed manual the
但是当我尝试手动的时候
ssh $LOGIN@$machine
then ssh fail on WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED
然后ssh失败警告:远程主机识别已更改
but from the expect I cant to catch this errors in /tmp/erros
但是从预期我无法在/ tmp / erros中捕获这个错误
please advice what’s is wrong ? why 2>/tmp/errors
not capture the errors?
请指出什么是错的?为什么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"
1 个解决方案
#1
1
spawn
does not understand I/O redirection. Replace
spawn不了解I / O重定向。更换
spawn ssh $LOGIN@$machine 2>/tmp/errors
with either
spawn ssh $LOGIN@$machine -E /tmp/errors
# -E log_file tells ssh where to write the error log instead of stderr
or
spawn sh -c "ssh $LOGIN@$machine 2>/tmp/errors"
#1
1
spawn
does not understand I/O redirection. Replace
spawn不了解I / O重定向。更换
spawn ssh $LOGIN@$machine 2>/tmp/errors
with either
spawn ssh $LOGIN@$machine -E /tmp/errors
# -E log_file tells ssh where to write the error log instead of stderr
or
spawn sh -c "ssh $LOGIN@$machine 2>/tmp/errors"