Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.