【发布时间】:2018-10-01 14:42:52
【问题描述】:
我知道有很多关于它的讨论,但我需要你帮助解决 ssh 远程命令退出代码。我有那个代码:
(scan 是一个在给定文件中扫描病毒的脚本)
for i in $FILES
do
RET_CODE=$(ssh $SSH_OPT $HOST "scan $i; echo $?")
if [ $? -eq 0 ]; then
SOME_CODE
扫描有效,如果发现病毒,则返回 0 或(1 表示错误)或 2。但不知何故,我的返回码总是 0。即使我扫描了病毒。
这里是set -x 输出:
++ ssh -i /home/USER/.ssh/id host 'scan Downloads/eicar.com; echo 0'
+ RET_CODE='File Downloads/eicar.com: VIRUS: Virus found.
code of the Eicar-Test-Signature virus
0'
如果我在没有 ssh 的“远程”机器上运行这些命令,这是输出:
[user@ws ~]$ scan eicar.com; echo $?
File eicar.com: VIRUS: Virus found.
code of the Eicar-Test-Signature virus
2
我只想要返回码,我不需要scan 的所有其他输出。
!更新!
看来,echo 是问题所在。
【问题讨论】:
标签: linux bash shell unix scripting