Please review error routines in my ksh script

The script distributes files from an AIX server using iether ftp or sftp depending on the constraint of the destination server. I am interested in having the error checking routine critically reviewed. I will only include an excerpt from the script concerning error trapping: (where $FTP_OUT is the log captured for either an "ftp" or an "sfpt" transfer)

Check_for_errors()
{
      set -x


      RESULT=`egrep -c "not found|No such|refused|failed|error|timed out|not exist|denied|Connection closed|STOR fails|not authorized|timeout|Not connected" $FTP_OUT`
      if [[ ! -s $FTP_OUT ]] ; then
         error_reporting
         ERROR_MSG="** FAILURE **"
         echo "    No $ftpflag log file produced" >> $TEMP_LOGF
         echo "    Abandoning transfer. " >> $TEMP_LOGF
      elif [[ $RESULT -gt 0 ]] ; then
         # The existence of "Transfer Complete" doesn't guarentee a successful result, however it must be present for a successfil result.
         # Checking for it's existance excludes the possibility of a null log file or an unknown error type.
         error_reporting
         ERROR_MSG="** FAILURE **"
      else
         echo "    FTP Success for interface $ftpflag ::: ${ftpfile} " >> $TEMP_LOGF
      fi
      rm -f $FTP_CMD
      rm -f $FTP_OUT
}

This seems OK to me!! Did you try out?

Yes, I've tried it and it works, but how do I know I've covered every error possibility. Say, I missed an error in the "egrep" list, The routine might fail to detect an error.

In that case, force that to fail in all terms (Trial & Error). Else, echo the line you get after the transfer, let the user review and proceed! :slight_smile:

Actually, the routine is below, posted a different version:

Check_for_errors()
{
      set -x

      RESULT=`egrep -c "not found|allow|permissions|No such|refused|failed|error|timed out|not exist|denied|Connection closed|STOR fails|not authorized|timeout|Not connected" $FTP_OUT`
      if [[ ! -s $FTP_OUT ]] ; then
         error_reporting
         ERROR_MSG="** FAILURE **"
         echo "    No $ftpflag log file produced" >> $TEMP_LOGF
         echo "    Abandoning transfer 4. " >> $TEMP_LOGF
      elif [[ $RESULT -gt 0 ]] ; then
         error_reporting
         ERROR_MSG="** FAILURE **"
      else
         echo "    FTP Success for interface $ftpflag ::: ${ftpfile} " >> $TEMP_LOGF
      fi
      rm -f $FTP_CMD
      rm -f $FTP_OUT
}

Thanks

You could use ignore case option too!!

Thankyou for your comments pikK45. I don't have the luxury of trial and error, other than the extensive testing I've done in an attempt to get all the "error texts". It's a batch process.
Cheers

All the best! :slight_smile: