Jump to content

Cron Job time and date settings


Recommended Posts

Hi All,

 

Am trying to schedule some cron job tasks and am alightly confused with the right date and time settings for the following scenarios

 

(1) Run a php file every week on a sunday at 9AM

1 9 * * 7

 

(2) Run a php file every two weeks on a monday at 11AM

2 11 * * 1

 

Am i right with the above settings? If not can anyone please correct me.

 

Cheers

Link to comment
https://forums.phpfreaks.com/topic/153392-cron-job-time-and-date-settings/
Share on other sites

Hope this helps:

 

*    *  *  *    *  command to be executed

-    -    -    -    -

|    |    |    |    |

|    |    |    |    +----- day of week (0 - 6) (Sunday=0)

|    |    |    +------- month (1 - 12)

|    |    +--------- day of month (1 - 31)

|    +----------- hour (0 - 23)

+------------- min (0 - 59)

 

Yours should be

 

0 9 * * 0

 

and I dont know how you would do the second one!

 

 

Cron doesn't have an option of every other day of the week, at least, not that I know of.  But you can test to see if the cronjob was run last week via a small bash script:

 

if test -f /dir/lastweek
then
       rm /dir/lastweek
       exit
fi
touch /dir/lastweek
run the job

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.