2014-11-04 49 views
1

以下期待脚本将删除的文件/ var/tmp目录/文件远程机器如何捕捉期望从脚本

上,但标准误差之前的预期脚本做SSH远程机器上,

我把2>/tmp/errors为了从SSH

赶上错误,但我注意到,尽管SSH远程发送错误,我没有看到/tmp/errors文件

错误,但是当我tryed手册

ssh [email protected]$machine 

然后SSH失败的WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED

但从指望我不能赶上这个错误在/tmp/erros

请指教什么是错的?为什么2>/tmp/errors没有捕获错误?

expect_test=`cat << EOF 
set timeout 50 
spawn ssh [email protected]$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

喜伊坦你怎么样 - THX的更新 – maihabunash 2014-11-04 13:57:13

+1

我不知道,随便,如果你能在'使用重定向产卵“命令。如果你可以,至少,你可能需要引用它的tcl。这就是说,如果期望没有读取标准错误(并且我不记得如果是的话),你可以直接在'expect -c'执行,直到得到你想要的。 – 2014-11-04 14:00:04

+0

以超级用户身份复制:http://superuser.com/q/835794/4714 – 2014-11-04 16:15:24

回答

1

spawn不理解I/O重定向。更换

spawn ssh [email protected]$machine 2>/tmp/errors 

与任何

spawn ssh [email protected]$machine -E /tmp/errors 
# -E log_file tells ssh where to write the error log instead of stderr 

spawn sh -c "ssh [email protected]$machine 2>/tmp/errors"