Operating System - HP-UX
1833588 Members
4232 Online
110061 Solutions
New Discussion

Re: Checking response file in a script (ksh)

 
steven Burgess_2
Honored Contributor

Checking response file in a script (ksh)

Hi

I have a job that checks a file, creates a variable depending on the name of the file then renames the file once it has been sent. The problem I am having is checking the confirmation file that comes from the customer

so

DATE=$(date +%y%m%d)
CSVFILE=$(ls $DIR/$DATE[0-9][0-9].PAY | awk '{print $9}' | awk -F / '{print $6}' | cut -c1-8

The above gives me

03030401

01 = first file to have been sent today.

The problem I have is if I have to send more than one file in a day I will receive 2 response files, with a similar format as above

for eg

Yesterdays transfer failed. Today I am going to send

03030301.PAY

and Todays file

03030401.PAY

I should therefore receive from them.

03030401.CNF
and
03030402.CNF

Whats the best way to check that I have received the response files ? Bearing in mind the number of files that I have sent to them in a day and the file names I send will differ

I am no great script writer

Thanks in advance

Steve

take your time and think things through
10 REPLIES 10
Steve Steel
Honored Contributor

Re: Checking response file in a script (ksh)

Hi

You have a .CNF and a .PAY

ls -1 ./|grep PAY$| while read line
do
field=$(echo $line|cut -f1 -d".")
if [ -f $field".PAY" ] && [ -f $field".CNF" ]
then
echo $field".CNF" found
else
echo wrong
fi
done

ls -1 local directory and extract all .PAY
remove .PAY from name and in loop check
if .PAY and .CNF then ok else wrong.

Fill in what you want to do


Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
John Palmer
Honored Contributor

Re: Checking response file in a script (ksh)

This should be fairly easy...

cd
# Don't ls *.PAY in case it exceeds the number
# of arguments for a command. If this is not
# the case then use ls *.PAY and remove the
# if statement checking if it's a .PAY file
ls | {
while read FNAME
do
if [[ ${FNAME} != *(?).PAY ]];
then continue
fi
PREFIX=${FNAME%.PAY} # Remove the .PAY suffix

if [[ -f ${PREFIX}.CNF ]];
then continue
fi

# Here we have a .PAY without a corresponding
# .CNF file.

print "${FNAME} has no confirmation file!"
done
}

Regards,
John
James R. Ferguson
Acclaimed Contributor

Re: Checking response file in a script (ksh)

Hi Steven:

Assuming the sent and the received files reside in the same directory, something like this would work:

#!/usr/bin/sh
cd /tmp
for S in `ls [0-9][0-9]*.PAY`
do
R=${S%%.PAY}.CNF
ls ${R} >/dev/null 2>&1
if [ $? = 0 ]; then
echo "${R} received"
else
echo "${R} not received"
fi
done
exit 0

Regards!

...JRF...
steven Burgess_2
Honored Contributor

Re: Checking response file in a script (ksh)

Hi Steve

You are checking for every .PAY that there is a .CNF of the same name. I have just found that the .PAY is renamed to .PAZ which isn't a problem. The .CNF files are moved to another area and renamed, could be a problem.

For now though, there isn't necessarily a .PAZ with the same name ending .CNF

I could have

03030401.PAZ

and receieve

03030402.PAZ

How do I check that ?

Thanks in advance

Steve
take your time and think things through
steven Burgess_2
Honored Contributor

Re: Checking response file in a script (ksh)

Hi

Initially I was trying to define the receive files from the files that I had sent

CNFFILE=$( echo ${PAYPATH}/${CSVFILE} | /usr/bin/sed 's/\.PAY/\.CNF/g' | /usr/bin/awk -F / '{print $6}' )

But found I couldn't because they won't necessarily be the same

Steve
take your time and think things through
steven Burgess_2
Honored Contributor

Re: Checking response file in a script (ksh)

Hi James

Similar method to Steve, checking the name of the .PAY matches the .CNF.

Thanks

Steve
take your time and think things through
steven Burgess_2
Honored Contributor

Re: Checking response file in a script (ksh)

Sorry guys

I'm confusing you. lets stick with the .PAY and .CNF

I could have

03030401.PAY

and receieve

03030402.CNF

Thanks

Steve
take your time and think things through
John Palmer
Honored Contributor

Re: Checking response file in a script (ksh)

Your problem is difficult because there's no correlation between the name of the file that you send and the one that you receive.

Is there anything in the actual data that could be used to identify which is which? Also, you say that 'Yesterdays transfer failed. Today I am going to send ...', do you get something back to say that it failed?

Without some means of identification, the best you can hope to achieve is to flag up the fact that you haven't received confirmation for every file that you've sent.

Regards,
John
Carlos Fernandez Riera
Honored Contributor

Re: Checking response file in a script (ksh)

send ( )
{
SEND_NUM=$1

DATE=$(date +%y%m%d)
TDATE=$( TZ=CST-24 date +%y%m%d )
echo " SENDED FILE ${DATE}${SEND_NUM}" > ${DATE}${SEND_NUM}.PAY
touch ${TDATE}${SEND_NUM}.CNF
touch ${TDATE}${SEND_NUM}
}

check ( )
{
CHECKDATE=$1
for i in $CHECKDATE[0-9][1-9]
do
if [ -s $i.CNF ] ; then
echo $i.PAY Have been recived
else
echo $i.PAY Have been not recived yet
fi
done
}

send 01
send 02
check 030305
echo " CHANGIN SOME ONE "
echo " RECIVED 03030502.CNF" >03030502.CNF
check 030305
unsupported
steven Burgess_2
Honored Contributor

Re: Checking response file in a script (ksh)

Hi Chaps

I have found that a script spawned from this one has a task that removes the .CNF file. Therefore there is only ever on in the directory at any one time

k ching

Simple check then

# Now Check for the Response file
#
CNFFILE=$(ls -ltr ${PAYPATH}/${DATE}[0-9][0-9].CNF | awk '{print $9}' | awk -F / '{print $6}')
if [[ -f ${PAYPATH}/${CNFFILE} ]]
then
transferSuccess="YES"
else
logError "Payment confirmation file not received "
fi


Thanks for the input everyone

Steve
take your time and think things through