2017-07-07 46 views
0

我在bash小片段bash脚本爆发循环不发送邮件

retries = 3 

for ((i=0; i<retries; i++)); do 
    curl -1 --cipher ALL --connect-timeout 90 -T $zip_name ftps://ftp.box.com/Backup/$zip_name --user [email protected]:§fHyFSDF$o6 
    [[ $? -eq 0 ]] && break 
    echo "something went wrong, let's wait 6 seconds and retry" 
    sleep 6 
done 

[[ $retries -eq i ]] && { echo "This email is a notification of Failure" | mail -s "Failed" "[email protected]" ; exit 1; } 

上述循环应重试3次,如果有做卷曲一个错误,所以如果卷曲错误出现这应该邮寄到电子邮件。但是,为了测试它我撤销用户的访问,所以我期望的电子邮件,但是这并没有工作,我收到以下控制台上:

% Total % Received % Xferd Average Speed Time Time  Time Current 
           Dload Upload Total Spent Left Speed 
    0  0 0  0 0  0  0  0 --:--:-- 0:00:03 --:--:--  0 
curl: (9) Server denied you to change to the given directory 

为什么代码,如果访问,如果打破了第一次尝试撤销上传服务器

+0

https://www.gnu.org/software/bash/manual/html_node/Quoting.html#Quoting – hek2mgl

+0

@ hek2mgl你可以详细说明你想说的话? – Kittystone

+0

我说你需要引用(a)变量和(b)包含特殊字符的字符串。我在代码中看不到引号。 – hek2mgl

回答

0
retries = 3 

for ((i=0; i<$retries; i++)) 
do 
    curl -1 --cipher ALL --connect-timeout 90 -T $zip_name 
ftps://ftp.box.com/Backup/$zip_name --user [email protected]:§fHyFSDF$o6 
    if [[ $? -eq 0 ]] 
    then   
     break 
     echo "something went wrong, let's wait 6 seconds and retry" 
     sleep 6 
    fi 
done 

if [[ $retries -eq $i ]] 
then 
    echo "This email is a notification of Failure" | mail -s "Failed" "[email protected]" 
    exit 1 
fi 

你最好使用if语法我觉得,我注意到你没有正确引用retries变量。即与$重试,而不是重试和$我而不是我

+0

我试过你的变化以及..错误仍然存​​在完全一样。为什么卷曲断裂而不去? – Kittystone

+0

如果第一次curl命令成功,则循环会发生,但电子邮件不会发送,因为重试只会是0? –

+0

是的。如果试图在第四次重试之后尝试退出,它应该突破并发送电子邮件 – Kittystone