Retry Logic But In Cron

Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Retry Logic But In Cron
# 1  
Old 04-23-2020
Retry Logic But In Cron

Hard to explain but we get two sets of files in, and index file and image file. Often the image file arrives way later, so we just run this script I'm going to show in a second.
log="$log_dir/resub.`date +"%m%d%y"`.log"
ERRORFILE=`ls /apps/dwd/rip-robinprod/work/*err|wc -l`
dt=`date '+%d/%m/%Y_%H:%M:%S'`

cd $java_dir

if [ $ERRORFILE -gt 0 ]; then
   sed -i 's/�/-/g' $error_dir*.rpt
   echo "The below files have been resbumitted. " >> $log
   echo `ls -ltr $error_dir*err` >>$log
   /bin/java -cp "./TIPError.jar:./TIP31.jar:./TIP31msg_en_US.jar" ResubmitErrors -AuxprpawdRobin01 -P20904 >>$log
   echo "No Error Files Found $dt" >>$log ;\

This basically uses those jar files and tries to reconcile the files, if they don't work the files go back into a directory with the file extensions .err and rpt
Each time they do the it updates the time stamp. How can we retry like 5 times and then kick out an email that this has been resumitted 5 times please notify vendor?
# 2  
Old 04-24-2020
In the loop, will the .err files be removed on later success? How to tell new errors from old ones during the loop? Will there be leftovers from the last run?
What wait period between loops do you want?
# 3  
Old 04-24-2020
In the following, the index file is placed in the requests directory, and the image file in the temp directory. The index files can have different extensions to indicate grouping or priority.
The pid file is used to prevent subsequent invocations of the cron job from running.
You can periodically examine the contents of the temp and request directories for entries that older than some specified time.

cd /u/email
if [ -r /u/email/$ ]
    echo "Previous batch  still running" $(cat $
echo $proc >/u/email/$
list=$(ls requests|grep $BATCH)
if [ "$list" != "" ]
    for request in $list
    #do processing here          
    #if successful 
        mv requests/$request done
        mv temp/$request* done
       #echo "This one failed"
rm /u/email/$
echo finished at $(date)

# 4  
Old 04-24-2020
Not sure why you should need cron for your task, but this should run under it as well. Make sure it is run by bash! Replace your if construct with
if [ $(ls ${error_dir} | grep -c "\.err$") -eq 0 ]
  then  echo "No Error Files Found $dt" >>$log
  #           exit
  else  while   ((++CNT <= 5))
          do    echo "The below files have been resbumitted. " >> $log
                ls -ltr ${error_dir}*err >>$log
                /bin/java -cp "./TIPError.jar:./TIP31.jar:./TIP31msg_en_US.jar" ResubmitErrors -AuxprpawdRobin01 -P20904 >>$log
                [ $(ls ${error_dir} | grep -c "\.err$") -eq 0 ] && break
                sleep 5
        if (( CNT == 5))
          then  mail "resumitted 5 times please notify vendor"
          else  echo "error corrected after $CNT retries"
        unset CNT

Be aware that you need to check for the error files in every loop. Check the mail stuff and adapt to your system.
Login or Register to Ask a Question

Previous Thread | Next Thread

2 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

If then else - Retry operation

I need to read a file line by line, then depending on the contents of each line, type in a code that will get written to an array. The problem I have is when I ask the user to confirm the input code, if it is wrong, how do i Return to ask again? Any thing I try increments the file to the next... (6 Replies)
Discussion started by: kcpoole
6 Replies

2. Shell Programming and Scripting

Retry upon FTP failure

I am using the following code in a C Shell script to transfer files to a remote server: ftp -n <<DO_FTP1 quote user $user_name quote pass $password ascii put $js_file_name bin put $FinalZipFile quit DO_FTP1 This code works great except on those rare occasions... (8 Replies)
Discussion started by: phudgens
8 Replies
Login or Register to Ask a Question

Featured Tech Videos