Everyday we will receive 33 files in our source directory(/prd/pk) with the current date. Once our jobs are completed all the 33 files immediately will be moved to backup folder (/prd/pk/backup).
Now, I need to check between source file directory (/prd/pdk) and backup file directory based on date to ensure that all files are received for current date.
If not, I need to display how may files are missed for current date.
It seems more like this would be quicker and give the answer required:-
#!/bin/ksh
Date=`date "+%Y%m%d"`
Req_count=33
cd /prd/pdw
count=`ls -1d *${Date}*|wc -l`
if [ $count -ne $Req_count ]
then
((Shortfall=$Req_count-$count))
echo "You have only got $count files. You are $Shortfall short."
exit 99
fi
Set the value in red as applicable if your needs change.
Finding no files will give you an error message to standard error from the ls and the count will be zero. You could remove the message by changing that line to have:-