Sponsored Content
Top Forums UNIX for Beginners Questions & Answers ksh script to validate the record count status Post 303045438 by senmng on Friday 20th of March 2020 08:17:26 PM
Old 03-20-2020
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.


Code:
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

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

replaying a record count with another record count

i use unix command to take the record count for a file1 awk 'END{print NR}' filename i already have a file2 which conatin the count like ... .. rec_cnt=100 .. .. I want to replace the record in the file2 using the record i take from file1. suggest me some simple ways of doing it... (2 Replies)
Discussion started by: er_zeeshan05
2 Replies

2. Shell Programming and Scripting

HELP WITH .ksh script converting the exit status

Hi Can someone help me please? In a standard UNIX .ksh script, if you have the exit status..say 5...what line do you have to enter into the script for this number to be automatically converted to its actual exit reason by looking up the exit status file...wherever that is? thanks angus (1 Reply)
Discussion started by: angusyoung
1 Replies

3. Shell Programming and Scripting

Validate record count

Hi all How to verify the number of records in case of delimited file, If the file has records. And then if it is not equal to mentioned no. of records, email is triggered and file is moved to bad directory path. Example ----- input file = a.txt bad directory path : /usr/bin/bad (6 Replies)
Discussion started by: balaji23_d
6 Replies

4. Shell Programming and Scripting

Help in writing a KSH script to filter the latest record?

Hi All, I have a text file with the folowing content. BANGALORE|1417|2010-02-04 08:41:04.174|dob|xxx BANGALORE|1416|2010-02-04 08:23:19.566|dob|yyy BANGALORE|1415|2010-02-04 08:20:14.497|dob|aaa BANGALORE|1414|2010-02-04 08:19:40.065|dob|vvv BANGALORE|1413|2010-02-04... (4 Replies)
Discussion started by: Karpak
4 Replies

5. Shell Programming and Scripting

exit status from ksh script exec from java using runtime

how do i get the exit status from a ksh or perl script executed in a java program using Runtime? (1 Reply)
Discussion started by: twk
1 Replies

6. Shell Programming and Scripting

Exit status of the ksh Script

Hi Im trying to write a script that will archive some file using java program.Below is the part of the script that I use and my problem is that the script always return with status 0.Below is part of my script(end part) purge.ksh echo "No of files before tar :... (4 Replies)
Discussion started by: saachinsiva
4 Replies

7. Shell Programming and Scripting

Print record count of a file using shell script

HI, I need to print the record count of a file using shell script. If the record count of a file excluding header and trailer record if greater than zero then print 'Record count of a file is xxxx records'. If the record count is zero print 'zero records' Thanks Mahendra (1 Reply)
Discussion started by: mmeda
1 Replies

8. Shell Programming and Scripting

Validate file count in korn shell script

Hi, I have files in the directory like below which I need to validate if all the required files are present. A_B_001 of 002_time1.txt A_B_002 of 002_time1.txt A_B_001 of 001_time2.txt Scenarios- a)If file with 001 of 002_time1 or 002 of 002_time1 is missing in the folder,script should... (6 Replies)
Discussion started by: aneeta13
6 Replies

9. Shell Programming and Scripting

Any Sample ksh script to validate all the database objects

Hi, I need a sample script to validate all the database objects like 1. table structure(columns, datatypes,key contraints if any) 2. synonyms 3. grants 4. indexes ....etc thank you! (2 Replies)
Discussion started by: srikanth_sagi
2 Replies

10. UNIX for Beginners Questions & Answers

Ssh script to validate ssh connection to multiple serves with status

Hi, I want to validate ssh connection one after one for multiple servers..... password less keys already setup but now i want to validate if ssh is working fine or not... I have .sh script like below and i have servers.txt contains all the list of servers #/bin/bash for host in $(cat... (3 Replies)
Discussion started by: sreeram4
3 Replies
PCAP_LOOP(3PCAP)														  PCAP_LOOP(3PCAP)

NAME
pcap_loop, pcap_dispatch - process packets from a live capture or savefile SYNOPSIS
#include <pcap/pcap.h> typedef void (*pcap_handler)(u_char *user, const struct pcap_pkthdr *h, const u_char *bytes); int pcap_loop(pcap_t *p, int cnt, pcap_handler callback, u_char *user); int pcap_dispatch(pcap_t *p, int cnt, pcap_handler callback, u_char *user); DESCRIPTION
pcap_loop() processes packets from a live capture or ``savefile'' until cnt packets are processed, the end of the ``savefile'' is reached when reading from a ``savefile'', pcap_breakloop() is called, or an error occurs. It does not return when live read timeouts occur. A value of -1 or 0 for cnt is equivalent to infinity, so that packets are processed until another ending condition occurs. pcap_dispatch() processes packets from a live capture or ``savefile'' until cnt packets are processed, the end of the current bufferful of packets is reached when doing a live capture, the end of the ``savefile'' is reached when reading from a ``savefile'', pcap_breakloop() is called, or an error occurs. Thus, when doing a live capture, cnt is the maximum number of packets to process before returning, but is not a minimum number; when reading a live capture, only one bufferful of packets is read at a time, so fewer than cnt packets may be processed. A value of -1 or 0 for cnt causes all the packets received in one buffer to be processed when reading a live capture, and causes all the packets in the file to be processed when reading a ``savefile''. (In older versions of libpcap, the behavior when cnt was 0 was undefined; different platforms and devices behaved differently, so code that must work with older versions of libpcap should use -1, nor 0, as the value of cnt.) callback specifies a pcap_handler routine to be called with three arguments: a u_char pointer which is passed in the user argument to pcap_loop() or pcap_dispatch(), a const struct pcap_pkthdr pointer pointing to the packet time stamp and lengths, and a const u_char pointer to the first caplen (as given in the struct pcap_pkthdr a pointer to which is passed to the callback routine) bytes of data from the packet. The struct pcap_pkthdr and the packet data are not to be freed by the callback routine, and are not guaranteed to be valid after the callback routine returns; if the code needs them to be valid after the callback, it must make a copy of them. RETURN VALUE
pcap_loop() returns 0 if cnt is exhausted, -1 if an error occurs, or -2 if the loop terminated due to a call to pcap_breakloop() before any packets were processed. It does not return when live read timeouts occur; instead, it attempts to read more packets. pcap_dispatch() returns the number of packets processed on success; this can be 0 if no packets were read from a live capture (if, for example, they were discarded because they didn't pass the packet filter, or if, on platforms that support a read timeout that starts before any packets arrive, the timeout expires before any packets arrive, or if the file descriptor for the capture device is in non-blocking mode and no packets were available to be read) or if no more packets are available in a ``savefile.'' It returns -1 if an error occurs or -2 if the loop terminated due to a call to pcap_breakloop() before any packets were processed. If your application uses pcap_breakloop(), make sure that you explicitly check for -1 and -2, rather than just checking for a return value < 0. If -1 is returned, pcap_geterr() or pcap_perror() may be called with p as an argument to fetch or display the error text. SEE ALSO
pcap(3PCAP), pcap_geterr(3PCAP), pcap_breakloop(3PCAP) 24 December 2008 PCAP_LOOP(3PCAP)
All times are GMT -4. The time now is 10:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy