Fooling files

I have scenario wherein ...

There are files of same name getting generated on a daily basis .
I have got the file names in a file . Now what my script does is read the file , check for existence of filename and increment a counter by 1 .

Now sometimes what happens is that the previous day's file gets counted in case the file for today has not yet GNTDand overwrtes the prev days file .

To handle this case of not taking into account the previous days file . I have put in a check which checks the file creation date should be equal to current date .

today_date=`date +'%d'`

ls -lrt file_to_be_checked.txt | awk {'print$7'}` -ne $today_date .

This needs to be integrated ... but i am getting confused when trying to do the same into

cntr=0;
while read line;
do [[ -e "$line" ]] && let cntr=$cntr+1
done < file_list

Need to put my file date check somewhere when rading the file_list and checking for the existence .

Any suggestions appreciated
.. Any suggestions apppreciated .

What Shell do you use?

What does "has not yet GNTDand " mean?

hi

I am using /usr/bin/sh and SUN Solaris server

has not yet GNTDand = has not yet been generated and ....

One idea is to create a reference file with "touch" with a timestamp at the start of the day, then compare the timestamp.
Not tested with your exact shell.

YYYYMMDD="`date +%Y%m%d`"       # Reversed date yyyymmdd
REFERENCE=/var/tmp/reference.${YYYYMMDD}.$$
touch -t ${YYYYMMDD}0000 ${REFERENCE}  # Start of today

cntr=0
while read line
do
    if [ -e "${line}" ]
    then
        if [ "${line}" -nt "${REFERENCE}" ]
        then
            let cntr=$cntr+1
        fi
    fi
done < file_list
rm "${REFERENCE}"
1 Like

Hi methyl

Thanks for ur help ... ur script tickled my brains gray matter and what i have done is this

curr_date=`date +'%d'`
cntr=0;
while read line
do
if [ -e "${line}" ]
then
if [ `ls -lrt $line | awk {'print$7'}` -eq $curr_date ]
then
let cntr=$cntr+1
fi
fi
done < file_list

@ultimax

Your script will only work if the current day of the month is a double digit.
You may find that "date +%e" is more useful than "date +%d".

Appreciate your Keen observation ...

Thanks mate