Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Test File creation date?!?!

Status
Not open for further replies.

Scunningham99

Programmer
Sep 20, 2001
815
GB
Hi All

I have no experience in UNIX script. so please bear with me! Crontab uploads a file namely 'rcc1_gvc_sales.csv' every morning! this is reliant on the file being refreshed by another server every day, else same file is uploaded again. This is bad, so my aim is to code a check which checks the date of the file.

Ie. if the file creation date is NOT = to todays date then touch the file so it is blank, hence blank file is uploaded, meaning the same file has not being uploaded twice.

the problem i have got is i do not know the command to check creation date or somewat of file!!!!!


if [ rcc1_gvc_sales.csv != "todays date HELP" ]; then

touch rcc1_gvc_sales.csv #to make the file blank

fi;

ANY CLUES WOULD BE GREATLY APPRECIATED!!!
 
Hi
Try this
datein=`date +%d" " +%b` # gives 28 Mar
datestr=`ls -l rcc1_gvc_sales.csv |cut -c41-47`
#gives 27 Mar

if[ "${datein}" != "${datestr} ]
then
touch rcc1_gvc_sales.csv
fi

Regards
DickieBird
;) Dickie Bird
db@dickiebird.freeserve.co.uk
 
Hi
How about this:

todaymo=`date +%b`
todayda=`date +%d`
today=`ls -lisa rcc1_gvc_sales.csv | cut -c53-58 | grep $todaymo | grep $todayda`
if (test -z "$today") then
cp /dev/null rcc1_gvc_sales.csv
fi
 
Thanks for reply!!

I have done the following, however the command touch does not clear the file, anyone know the command to truncate the file!!

#test for file created today ie access time of 0 days
[ `find . -name rcc1_gvcsales.csv -mtime 0` ]


if [[ $? = 1 ]] #check status of find command
then
touch rcc1_gvcsales.csv #to make the file blank

else
echo Successful Completion 0
fi
 
delete it then touch it
ie
rm rcc1_gvcsales.csv
touch rcc1_gvcsales.csv

or perhaps save it instead
mv rcc1_gvcsales.csv rcc1_gvcsales.csv.prev
[pipe]
Dickie Bird
db@dickiebird.freeserve.co.uk
 
though mrregan's cp /dev/null rcc1_gvc_sales.csv
will give an empty file, too Dickie Bird
db@dickiebird.freeserve.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top