Reputation: 7243
How to configure a cron job to run every night at 2:30? I know how to make it run at 2, but not 2:30.
Upvotes: 389
Views: 725071
Reputation: 11
0 30 2 * * *
0 - first second of an minute
30 - 30th minute of an hour
2 - 2nd hour of an day
(*) - every day
(*) - every month
(*) - every day of week
But the seconds is optional
use this site for reference : http://www.cronmaker.com/
Upvotes: 0
Reputation: 21
30 2 * * * Every Day at 2:30 Am
30-31 2 * * * Every Day at 2:30 -31 am
Along with he answers its important to understand the cron expressions , i face a lot of difficulty in understanding . But an intuitive way to understand is given here .
Upvotes: 2
Reputation: 14232
As an addition to the all above mentioned great answers, check the https://crontab.guru/ - a useful online resource for checking your crontab syntax.
What you get is human readable representation of what you have specified.
See the examples below:
Upvotes: 4
Reputation: 149
30 2 * * * wget https://www.yoursite.com/your_function_name
The first part is for setting cron job and the next part to call your function.
Upvotes: 1
Reputation: 290255
As seen in the other answers, the syntax to use is:
30 2 * * * /your/command
# ^ ^
# | hour
# minute
Following the crontab standard format:
+---------------- minute (0 - 59)
| +------------- hour (0 - 23)
| | +---------- day of month (1 - 31)
| | | +------- month (1 - 12)
| | | | +---- day of week (0 - 6) (Sunday=0 or 7)
| | | | |
* * * * * command to be executed
It is also useful to use crontab.guru to check crontab expressions.
The expressions are added into crontab
using crontab -e
. Once you are done, save and exit (if you are using vi
, typing :x
does it). The good think of using this tool is that if you write an invalid command you are likely to get a message prompt on the form:
$ crontab -e
crontab: installing new crontab
"/tmp/crontab.tNt1NL/crontab":7: bad minute
errors in crontab file, can't install.
Do you want to retry the same edit? (y/n)
If you have further problems with crontab not running you can check Debugging crontab or Why is crontab not executing my PHP script?.
Upvotes: 83
Reputation: 2713
To edit:
crontab -e
Add this command line:
30 2 * * * /your/command
MIN HOUR DOM MON DOW CMD
MIN Minute field 0 to 59
HOUR Hour field 0 to 23
DOM Day of Month 1-31
MON Month field 1-12
DOW Day Of Week 0-6
CMD Command Any command to be executed.
Restart cron with latest data:
service crond restart
Upvotes: 185