Re: A unix cron job question

  • From: "Humberto Rodriguez" <sub@xxxxxxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Fri, 25 Jun 2010 20:42:31 -0400

Probably the easiest way is to use PHP and the seconds from the Unix Epoch 
(Jan 1, 1970 GMT).  To go back 30 days, you may do:

$now= date("U");
$then= $now - (60*60*24*30);

Then, if you want the ISO-8601 date:
$date= date("c", $now);

For the RFC-2822 date:
$date= date("r", $now);

There are many more formats for getting the date and time anyway you want, 
all the Unix choices.  Look at the function date() in php.net.

HIH,

Humberto

----- Original Message ----- 
From: "Lafond, Eileen" <Eileen.Lafond@xxxxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Friday, June 25, 2010 6:29 PM
Subject: A unix cron job question


We run many cron jobs daily that create a log file per cron job.  This 
creates many log files over time.  I think that we have about 33000 files 
right now.

I am trying to create a cron job that will run once a month and delete all 
the log files that are more than thirty days out.

I am trying now just to put the specification document together and I am 
having a difficult time with the details of the code.

I was thinking of using the following:

mydate="`date +"%m%d%y%H%M""

I cannot figure out how to write the code to go thirty days back and when I 
get that, I will then create a delete statement to delete the rest of the 
files.

Does anyone have any idea as to how I can use the mydate above to figure out 
thirty days bac?

Or am I doing this the wrong way and there might be an easier way to do it?



Thanks for any help.

Eileen La Fond
Work Phone: (206) 386-0011
Email: Eileen.lafond@xxxxxxxxxxx

__________
View the list's information and change your settings at
//www.freelists.org/list/programmingblind


__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: