0403-016 Cannot find or open the file in If Statement

Hi,

I am comparing the number of records in the .bad record from sql loader, if it is higher than the number passed in as an argument, the program should exit. However, I constantly receive the error "

0403-016 Cannot find or open the file.

" on the line with the if statement " elif [ $bad_record_count <= $error_limit ]; ". The code is below and error_limit=$1 . Any help is appreciated.

if [[ $chksanret = 0 ]]; then
   sqlldr CONTROL=$LOAD_HOME/lndcntl/mrkdwndly.ctl LOG=$LOAD_HOME/loadresults/mrkdnasapbar.log  \
      BAD=$LOAD_HOME/loadresults/mrkdnasapbaz.bad DATA=$LOAD_HOME/$fnamem     \
      USERID=$OSLDR ERRORS=999 DISCARD=$LOAD_HOME/loadresults/mrkdnasaptoss.dis \
      DISCARDMAX=5 DIRECT=TRUE
   retcode=`echo $?`
   bad_record_count=$(< $LOAD_HOME/loadresults/mrkdnasapbaz.bad wc -l)
   if [[ $retcode = 0 ]]
   then
     cp $LOAD_HOME/$fnamem $LOAD_HOME/ARCHIVE/LND_ASAP_PRCCHG_DYLY.txt_$DATE
   elif [ $bad_record_count <= $error_limit ];
   then
     cp $LOAD_HOME/$fnamem $LOAD_HOME/ARCHIVE/LND_ASAP_PRCCHG_DYLY.txt_$DATE
   else
     exit 12
   fi
else
   exit $chksanret

Hi,
It's wrong

elif [ $bad_record_count <= $error_limit ];

expected

elif [ $bad_record_count -le $error_limit ];

and else

if [[ $chksanret = 0 ]]

expected

if [ $chksanret = 0 ]

or

if [ $chksanret -eq 0 ]

or

if [[ $chksanret == 0 ]]

--- Post updated at 21:30 ---

I hope this is not the whole file and there is a final "fi"

1 Like

And

retcode=`echo $?`

works but is bad style. Should be simply

retcode=$?
1 Like

Despite nezabudka's and MadeInGermany's comments being correct they don't explain the error message. It comes from the shell interpreting the < as the redirection operator for stdin, and it doesn't find the file named the $error_limit 's value. Escaping it would have helped circumvent that error, but had immediately stumbled over the next one: <= is not an accepted operator (in bash at least - you didn't mention the shell you use), use ! ... \> in lieu. Be aware that either of these compare values lexicographically using the current locale, so 145 would be considered less than 87, for instance. That's where nezabudka's proposals to use integer / numerical operators (like -le ) come into play.

1 Like