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 dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Manipulation / Cron Job

Status
Not open for further replies.

aconite

Programmer
Dec 10, 2000
1
US
Greetings:

I don't have the ability to install new modules on my ISP's server
(running Perl 5.05), and they are a bit sticky about such things. So, I
was wondering if any of you might be able to help me with a code
snippet. The problem is as follows:

1) I want to execute a function to clean up my database every other
Monday. I can easily have my ISP institute a cron job on the server to
kick off my Perl script that cleans the database, but the problem with
cron is that it can only be told to run every Monday.

2) When my Perl script executes every Monday, I want to have some code
in it to check and see if this is an even or odd Monday and either exit
or perform the functions for cleaning the database. Does anybody have
any code snippets or references for how I might check the date, and then
determine if this is the Monday that I want to execute the database
cleaning functions?

Thanks,

Mark

 
perldoc -f localtime

will give you all of the info you need on the date functino, that's pretty simple to find out... As always, I hope that helped!

Disclaimer:
Beware: Studies have shown that research causes cancer in lab rats.
 
For more info, check out hte FAQ in this section on getting help (It's on the tab at the top of the page) or see hmerril's tip post below.

MWB As always, I hope that helped!

Disclaimer:
Beware: Studies have shown that research causes cancer in lab rats.
 
You could write a flag to your database or filesystem. The first time you set it to 0 and run your functions. The next monday, set it to 1 and exit. The next monday, set it to 0 and run your functions, etc.

You could try to do it by date, but that will have problems since you have to deal with daylight savings, leap years, etc. Let cron handle that stuff, that's what it was built for.
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
Well, you could also have a small text file consisting of one integer, and you could set it to 1 the first Monday, 0 the next, 1 the next, and so on and so forth. I think that's what tom means, right?
As always, I hope that helped!

Disclaimer:
Beware: Studies have shown that research causes cancer in lab rats.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top