需要知道linux机器上rsync的状态

时间:2013-05-27 10:13:09

标签: linux rsync

我正在通过rsync从生产服务器同步我的备份服务器,但现在我想实现失败通知。当我试图获取rsync命令的状态时,它不会在成功时给我status = 0。请告诉我如何实现此功能。

    failureMailFlag=0

rsync --timeout=600 -e ssh -avzr --delete $sourcePath/weblayout/ $destination:$destinationPath/weblayout/ --stats -i > $fileCreationPath/$tempfile 2>&1
 rStatus=$?
    if [ $rStatus  == "0" ]
    then
        echo -e "$startdate\t\tweblayout\t\t$starttime\t\t$(date +"%m-%d-%Y %r")\t\tSuccess\t\t" >> $fileCreationPath/RsyncLog.txt

    else
        echo -e "$startdate\t\tweblayout\t\t$starttime\t\t$(date +"%m-%d-%Y %r")\t\tError\t\t">> $fileCreationPath/RsyncLog.txt
        failureMailFlag="1"
        cat $failureMail $tempfile >> $fileCreationPath/finalFailureMail.mai
            wablayout=weblayout
            varFailureMail=${varFailureMail}${wablayout}
fi

if [ $failureMailFlag == "1" ]
    then
    cat $fileCreationPath/*.mail finalFailureMail.mai $fileCreationPath/$varFailureMail $fileCreationPath/$tempfile | mailx -s "Failure Mail notification for RSYNC" $EmailSent
    else
    echo "successfully run"
fi

2 个答案:

答案 0 :(得分:0)

尝试:

if [ $rStatus -eq "0" ]

==是字符串而不是整数我认为

答案 1 :(得分:0)

使用;而不是2>& 1,如下所示

rsync --timeout=600 -e ssh -avzr --delete $sourcePath/weblayout/ $destination:$destinationPath/weblayout/ --stats -i > $fileCreationPath/$tempfile ; rStatus=$?