简体   繁体   English

如何在脚本中指出如果scp失败,请尝试wget

[英]How to tell in the script that if the scp failed, try wget

I have this script : 我有这个脚本:

cd /tmp/
scp user@8.8.4.1:/onboot/OTA.sh /tmp -i /usr/script/id 2> /dev/null
if
chmod 775 /tmp/OTA.sh
/tmp/OTA.sh &
sleep 30
rm -rf /tmp/OTA.sh

fi

I want to tell in the script that if the scp failed, try wget 我想在脚本中告诉您,如果scp失败,请尝试wget

man scp

EXIT STATUS
     The scp utility exits 0 on success, and >0 if an error occurs.

The exit status can be accessed using the variable $? 可以使用变量$?访问退出状态$? in bash. 猛扑

$? $? contains exit code of last called command. 包含上次调用命令的退出代码。 You can simply check if its non-zero: 您可以简单地检查其非零值:

scp user@8.8.4.1:/onboot/OTA.sh /tmp -i /usr/script/id 2> /dev/null
if [[ $? -ne 0 ]]
then
    #wget here
fi

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM