how to create cron jobs for part of the day

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Aleale
Forum Newbie
Posts: 5
Joined: Wed Oct 06, 2010 5:03 pm

how to create cron jobs for part of the day

Post by Aleale »

hi all,

just to simplify what posted yesterday,

I'd like to set a cron job every minute but only from 2pm to 4pm of a specific day, clearly without having to set 120 different jobs.

as secondary goal I'd like to be able to modify with ease the interval (for instance fro 11am to 3pm)

is it possible?

thanks!

Ale
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: how to create cron jobs for part of the day

Post by Jonah Bron »

Probably. I've never actually set up a CRON job myself, so I don't know how to do that particular thing. If you haven't already, you should read some tutorials on the subject.

http://www.google.com/search?q=cron+tutorial
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: how to create cron jobs for part of the day

Post by twinedev »

We have a client that I set up a cron that runs hourly to get a report of the orders during that hour and sync them to their server and e-mail a report to let them know if orders needed processed.

To make it simple, I have it run every hour of every day, and then at the top of the script make sure the hour is from 8am to 5pm and monday-friday, if not, it immediately exits. This was going to expand to allow the client through their admin set up times not to send it. (they in the end decided they didn't need this, they are fine with the extra e-mails piled up after a holiday).

-Greg
Aleale
Forum Newbie
Posts: 5
Joined: Wed Oct 06, 2010 5:03 pm

Re: how to create cron jobs for part of the day

Post by Aleale »

twinedev wrote:We have a client that I set up a cron that runs hourly to get a report of the orders during that hour and sync them to their server and e-mail a report to let them know if orders needed processed.

To make it simple, I have it run every hour of every day, and then at the top of the script make sure the hour is from 8am to 5pm and monday-friday, if not, it immediately exits. This was going to expand to allow the client through their admin set up times not to send it. (they in the end decided they didn't need this, they are fine with the extra e-mails piled up after a holiday).

-Greg

Good idea, I need a better "sampling resolution" but if I set it to check every quarter of hour, I think it'll be a good arrangement.
Sure it'd be better if I can trim directly the cron... but I think I can start the service in this way.

Thank you!
Aleale
Forum Newbie
Posts: 5
Joined: Wed Oct 06, 2010 5:03 pm

Re: how to create cron jobs for part of the day

Post by Aleale »

Jonah Bron wrote:Probably. I've never actually set up a CRON job myself, so I don't know how to do that particular thing. If you haven't already, you should read some tutorials on the subject.

http://www.google.com/search?q=cron+tutorial

Hi Jonah,

I already use cron commands, even though I'm not an expert. But since now I never found a manual or a solution that can create what I'm searching for. But Hope dies last :wink:

thank you!
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: how to create cron jobs for part of the day

Post by mikosiko »

Aleale wrote:hi all,

just to simplify what posted yesterday,

I'd like to set a cron job every minute but only from 2pm to 4pm of a specific day, clearly without having to set 120 different jobs.

as secondary goal I'd like to be able to modify with ease the interval (for instance fro 11am to 3pm)

is it possible?

thanks!

Ale
Is not this what you are looking for? (Mon is just an example)
[text]# Minute Hour Day of Month Month Day of Week Command
# (0-59) (0-23) (1-31) (1-12 or Jan-Dec) (0-6 or Sun-Sat)
* 14-16 * * Mon <your command>[/text]

this line will execute <your command> every minute, between 2PM and 4PM on Mondays for every Month for every day of the month (no tested on my side)
Post Reply