ksh script to validate the record count status

Hi - I have a KSH script to execute a oracle job to generate a data file and then ftp the same file to the downstream application. Here currently we have a validation check that not to send the file to downstream even if there is any partial record rejection with the data file. But i now want to transmit the file to the downstream if it's have single data of record irrespective of n number of rejection of records.Here is the snippet of code-

     LOG ="/dir/local/xyz`.log"

        TRNSERR=0
        CNT=1

        while [ $CNT -lt 4 ]
        do
                  ftp -nv < /local/cimspapp/CIMSbatch/script/FTP/CLAIMDNLD.ftp >> $sh_Trans

               cat $sh_Trans |grep -v bytes| awk '{print $1}' | egrep -e '530|425 > /dev/null
                # If error number found
                if [ $? -eq 0 ]
                then
                         echo "Error in Transmission" >> $sh_Trans
                         CNT=`expr $CNT + 1`
                        TRNSERR=1
                        
                else
                       grep -i "Not connected" $sh_Trans
                        if [ $? -eq 0 ]
                        then
                                echo "Connection Error" >> $sh_Trans
                                CNT=`expr $CNT + 1`
                                TRNSERR=1
                                sleep 100
                        else
                                TRNSERR=0
                                CNT=4
                        fi
                fi
        done

Hi

Where to beginn with?

  • Incorrect LOG assignment
  • Not using the $LOG
  • Using an unassigned $sh_Trans
  • Unrequired use of cat (can use grep for that, just 'add' the filename)
  • What is the output/content of $sh_Trans ?

And please, just to be sure (as I dont know this detail) in KSH:

cat  ~/randomfile-$$
echo $?

Because I wonder wether your error code check is working as you intend, or not.

hth

Apologize for the delay in response. Here are the little bit detailed code snippet where it starts with execution of procedure and check the error and execution status and then transmits the file.where in the proc1, it's checking the condition that if the rejected record is more than 0 then it assigns the value of errcode as 100 and setting user defined message for errmsg. Now i'd like to transmit the file even there is any rejection of records.

PRF=${DIR}/'file.log'
LGF=${DIR}'/file'`date '+%m%d%Y'`'.log'
sqlplus -s ${ORAUSER}/${ORAPASSWD}@${ORASRVC} <<EOF >> ${LGF}                               
set feedback off
set heading off
var errcode NUMBER
var errmsg VARCHAR2(1000)

whenever sqlerror exit -1
whenever oserror exit -1
execute pkg.proc1(:errcode,:errmsg);
print :errcode
exit :errcode;
EOF
if [[ $? -ne 0 ]] then

        ERR_LOG=`cat ${LGF}`
        write_log "Error in executing proc:$err_log"              
        mailx -s "Job Failure" xyzt@gmail.com  < ${file}
        if grep 'ORA-' ${PRF}
        then
                mailx -s "Job Failure" xyzt@gmail.com  < ${file}
                write_log "ORA error" 
                exit 1
        elif grep 'Error in executing proc1::' ${PRF}
        then
                mailx -s "Job Failure" xyzt@gmail.com  < ${file}
                write_log "handled error" 
                exit 1
        fi
elif [[ "$errcode" -ne 0 ]]
then
        err_log=`cat ${LGF}`
        write_log "Error in executing ClaimDownload:::: $ERR_LOG"
        mailx -s "Job Failure" xyzt@gmail.com  < ${file}
        exit 1
elif grep 'ORA-' ${PRF}  
then
        mailx -s "Job Failure" xyzt@gmail.com  < ${file
        write_log "ORA error" 
        exit 1
        else
        write_log "Proc1 executed successfully."
  shvar="/root/local/sftp_file2`date +'%m%d%Y%H%M'`.log"
        tranerr=0
        cnt=1
        while [ $cnt -lt 4 ]
        do
              ftp -nv < /opt/local/cimspapp/CIMSbatch/script/FTP/file2.ftp >> $shvar  # Try to send the file
               cat $shvar |grep -v bytes| awk '{print $1}' | egrep -e '530|425|426|421|450|451' > /dev/null
                if [ $? -eq 0 ]
                then
                       echo "Error in Transmission" >> $shvar
                      cnt=`expr $cnt + 1`
                        tranerr=1
                      else
                         grep -i "Not connected" $shvar
                        if [ $? -eq 0 ]
                        then
                             echo "Try Number: $cnt => FTP_FAILED , Connection Error" >> $shvar
                                cnt=`expr $cnt + 1`
                                tranerr=1
                                sleep 100
                        else
                                # Successful transmission
                                tranerr=0
                                cnt=4
                        fi
                fi
                done