문제

Using below script I successfully use to check .zip file created for each Application on a specific date and at a specific Destination to get confirmed whether my Backup is successful or not.

Till now I use to check Backup Time only for _2230 but now I also want to include _2250 in this check.

So what I did is just changed: BACKUPTIME="_2230 _2250", but It doesn't seem to be working as I'm neither getting SUCCESSFUL nor FAILED status in Log.

  1. Can you please direct me where is the problem in my script ?
  2. Could it have any impact on the speed of script I mean adding more TIME (_2230 and now _2250) to test for Backup ?

    #!/bin/sh
    
    DATE=`date +%Y%m%d -d "1 days ago"`
    DESTINATION="/Network/Storage/Backup"
    LOG="/Network/Storage/Backup"
    BACKUPTIME="_2230"
    
    APPLICATION="DATADEV TESTREV PRETEST"
    
    for C in $APPLICATION
    do
    
    cd $DESTINATION/$C/
    
    test -f $C$DATE$BACKUPTIME.zip
    
    if [ $? -eq 0 ]
    then
    echo "Backup SUCCESSFUL" >>$LOG/output.txt
    
    else
    echo "Backup FAILED" >>$LOG/output.txt
    
    fi
    
    done
    
도움이 되었습니까?

해결책

Using array:

    #!/bin/sh

    DATE=`date +%Y%m%d -d "1 days ago"`
    DESTINATION="/Network/Storage/Backup"
    LOG="/Network/Storage/Backup"
    BACKUPTIMES=(_2230 _2250)                   #Declare an array

    APPLICATION="DATADEV TESTREV PRETEST"

    for C in $APPLICATION
    do
        cd $DESTINATION/$C/
        success=false
        for BACKUPTIME in ${BACKUPTIMES[@]}; do #Iterate over the array
            test -f $C$DATE$BACKUPTIME.zip && success=true
        done
        if $success
        then
            echo "Backup SUCCESSFUL" >>$LOG/output.txt
        else
            echo "Backup FAILED" >>$LOG/output.txt
        fi
    done

Note: I have done minimal modification to your code, for easier understanding. There is still scope for optimization.

다른 팁

This might do it

dya=$(date +%y%m%d -d '1 days ago')
for fdr in datadev testrev pretest
do
  cd /network/storage/backup/$fdr
  pas=1
  for chk in ${fdr}${dya}_{2230,2250}
  do
    [ -f "$chk" ] || pas=0
  done
  (
    printf 'backup '
    (( pas )) && echo successful || echo failed
  ) >> /network/storage/backup/output.txt
done
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top