Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set up a cronjob every once monday at 7am

Tags:

php

Can anyone shed some light?

How to run a code once every Monday at 7am?

Is it like this?

* 7 * * 1
like image 650
DANLEE Avatar asked Oct 27 '14 05:10

DANLEE


2 Answers

This is how to setup a cronjob:

 # * * * * *  command to execute
 # │ │ │ │ │
 # │ │ │ │ │
 # │ │ │ │ └───── day of week (0 - 6) (0 to 6 are Sunday to Saturday, or use names; 7 is Sunday, the same as 0)
 # │ │ │ └────────── month (1 - 12)
 # │ │ └─────────────── day of month (1 - 31)
 # │ └──────────────────── hour (0 - 23)
 # └───────────────────────── min (0 - 59)

In your case, it will be

0 7 * * 1 command to execute

What does Asterisk (*) mean

The asterisk indicates that the cron expression matches for all values of the field. E.g., using an asterisk in the 4th field (month) indicates every month.


Sidenote

Other special characters in cronjobs

Slash ( / )

Slashes describe increments of ranges. For example 3-59/15 in the 1st field (minutes) indicate the third minute of the hour and every 15 minutes thereafter. The form "*/..." is equivalent to the form "first-last/...", that is, an increment over the largest possible range of the field.

Comma ( , )

Commas are used to separate items of a list. For example, using "MON,WED,FRI" in the 5th field (day of week) means Mondays, Wednesdays and Fridays.

Hyphen ( - )

Hyphens define ranges. For example, 2000-2010 indicates every year between 2000 and 2010 AD, inclusive.

Percent ( % )

Percent-signs (%) in the command, unless escaped with backslash (), are changed into newline characters, and all data after the first % are sent to the command as standard input.

See http://en.m.wikipedia.org/wiki/Cron

like image 172
baao Avatar answered Oct 20 '22 17:10

baao


00 7 * * 1

I used cron-expression-helper

like image 35
Julian Soro Avatar answered Oct 20 '22 19:10

Julian Soro