Linux 如何从expect脚本捕获标准错误
以下expect脚本将删除远程计算机上的文件/var/tmp/file 但在此之前,expect脚本在远程机器上执行ssh 我放置Linux 如何从expect脚本捕获标准错误,linux,bash,shell,ssh,expect,Linux,Bash,Shell,Ssh,Expect,以下expect脚本将删除远程计算机上的文件/var/tmp/file 但在此之前,expect脚本在远程机器上执行ssh 我放置2>/tmp/errors,以便从ssh捕获错误 但我注意到,尽管ssh-to-remote-send错误,但我没有看到/tmp/errors文件中的错误 但是当我尝试使用手册时 ssh $LOGIN@$machine 然后ssh失败警告:远程主机标识已更改 但是从预期来看,我无法在/tmp/erros 请告诉我怎么了?为什么2>/tmp/errors不捕获错误
2>/tmp/errors
,以便从ssh捕获错误
但我注意到,尽管ssh-to-remote-send错误,但我没有看到/tmp/errors
文件中的错误
但是当我尝试使用手册时
ssh $LOGIN@$machine
然后ssh失败警告:远程主机标识已更改
但是从预期来看,我无法在/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"
expect_test=`cat/tmp/errors
期待{
“{发送“是”\r;exp\u continue}”
字:{sleep 1;发送$PASSORD\r}
}
预期>{send“sleep 1\r”}
预期>{send“rm-f/var/tmp/file\r}
预期>{send exit\r}
预期eof
EOF`
expect-c“$expect\u remove\u文件”
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
这样的命令中使用重定向。如果可以,您可能至少需要为tcl引用它。这就是说,如果expect没有读取标准错误(如果它读取标准错误,我不会立即回忆起),您可能可以将其直接粘贴在expect-c
执行上,以获得您想要的结果。在超级用户上复制:
spawn sh -c "ssh $LOGIN@$machine 2>/tmp/errors"