0

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
    

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Its giving 6 messages in Log while I have only 3 Applications to check. It seems like its checking each application against both times (_2230 _2250) but despite of printing a single SUCCESS/FAILURE its printing 2 results per application for two times. But unfortunately that can't be the case as the backup of a single application is taken either on 2230 OR 2250 NOT at both times so only one message per application is expected.
1

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

1 Comment

Its giving 6 messages in Log while I have only 3 Applications to check. It seems like its checking each application against both times (_2230 _2250) but despite of printing a single SUCCESS/FAILURE its printing 2 results per application for two times. But unfortunately that can't be the case as the backup of a single application is taken either on 2230 OR 2250 NOT at both times so only one message per application is expected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.