Operating System - HP-UX
1828011 Members
1835 Online
109973 Solutions
New Discussion

comparing file date to system date

 

comparing file date to system date

I have a file which I would like to test nightly to make sure it's been updated prior to running an upload process. Can you tell me how I can read the file modified date and then compare it to the system date? My goal is create a script that will e-mail me when the file hasn't been updated for that day. Time of the modification doesn't matter, I just need to compare the dates.

Thanks,
Staci
5 REPLIES 5
James R. Ferguson
Acclaimed Contributor

Re: comparing file date to system date

Hi Staci:

One approach is as follows:

# touch -amt `date +%m%d`0000 /tmp/myref
# [ yourfile -nt /tmp/myref ] || mailx -s "yourfile not updated!" root < /dev/null

This creates a reference file whose modification timestamp is today at 00:00 hours. If 'yourfile' is *not* newer than that reference time, an email is generated to 'root' informing you of the condition.

Regards!

...JRF...
John Kittel
Trusted Contributor

Re: comparing file date to system date

I suppose you may get some better answers, but here is a quick one, -

if [[ `ll ${FILENAME} |awk '{ print$6,$7 }'` = `date +%b%e` ]]
then
# the dates match...
else
# the dates don't match, send email...
fi


( not sure how well this will work in all different circomstances)


- John
John Kittel
Trusted Contributor

Re: comparing file date to system date

I suppose you may get some better answers, but here is a quick one, -

if [[ `ll ${FILENAME} |awk '{ print$6,$7 }'` = `date +%b%e` ]]
then
# the dates match...
else
# the dates don't match, send email...
fi


( not sure how well this will work in all different circumstances)


- John
Muthukumar_5
Honored Contributor

Re: comparing file date to system date

You can try as,

#!/bin/ksh
file=/etc/testfile

if [[ "$(ls -l $file | awk '{ print $7,$8 }')" = "$(date +'%d %H:%M')" ]]
then
echo "File is updated" | mail mailid
else
echo "File is not updated" | mail mailid
fi

--
Muthu
Easy to suggest when don't know about the problem!

Re: comparing file date to system date

Thanks John. I was able to modify your response to get exactly what I needed.