Re: A unix cron job question

  • From: "qubit" <lauraeaves@xxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Wed, 30 Jun 2010 12:19:50 -0500

You can always use the touch command periodically to do this --  try the 
following:
run your cron every 30 days...in your cron, have the command first do the 
find command and delete anything older than /usr/whatever/somefile, then 
touch /usr/whatever/somefile
Then it will be ready for next time. Of course, you have to take care not to 
mess with somefile in between.

It is unfortunate I can't think of any command like the "at" command that 
lets you play around with dates. For example you can type such things as

$ at now + 1 week
execute commands here

It has a whole syntax for specifying relative dates and times, and that 
saves a lot of time munging numbers.

You can check the documentation for other time-relative commands.
Of course you can always compile a C program to do everything at that level 
and run it from the cron entry.

Have fun.;)
--le





----- Original Message ----- 
From: "Lafond, Eileen" <Eileen.Lafond@xxxxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Wednesday, June 30, 2010 11:26 AM
Subject: RE: A unix cron job question


Okay, so I guess I will check for a command like older filename since I want 
to delete the files older than thirty days old.

-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx 
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of qubit
Sent: Tuesday, June 29, 2010 11:28 PM
To: programmingblind@xxxxxxxxxxxxx
Subject: Re: A unix cron job question

No Eileen -- read the man page for the find command -- there is an actual
option
-newer filename
that evaluates to "true" when the current file being analyzed is newer than
the file specified. By "newer" I mean that its modified date is more recent.

You should get familiar with the find command.  It's one of those commands
that is like ls or sed or whatever that is extremely useful when you need to
analyze files.
 --le

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


Thanks for the code.

I went through it and it makes sense to me.  The part that says 'newer
somefile'  is apparently the place where I would put the calculation for
determining the files that are over thirty days old.  I don't know how to
create that code.

The original file name has the name of the data base and the name of the
cron and the date created as the following:
mydate="`date +"%m%d%y%H%M""

What would be the simplest way to determine the files that are over thirty
days old?

Thanks for any help,

Eileen La Fond
Work Phone: (206) 386-0011

-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of qubit
Sent: Friday, June 25, 2010 6:47 PM
To: programmingblind@xxxxxxxxxxxxx
Subject: Re: A unix cron job question

try the find command

for F in `find directory -type f ! -newer somefile -print`; do
echo "deleting $F"; rm $F
done

hope I'm remembering right -- I used to be a wild and crazy script writer.
Happy hacking.
--le



----- Original Message ----- 
From: "Lafond, Eileen" <Eileen.Lafond@xxxxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Friday, June 25, 2010 5: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

__________
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

__________
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: