Cron job beginners guide

Cron is one of the most useful utility that you can find in any linux based operating system. It is used to schedule commands at a specific time. These scheduled commands or tasks are known as “Cron Jobs” .

You can access cron job in directadmin by going to Advanced Features->cron job in your Directadmin control panel.

The typical format of a cron job is:

Minute(0-59) Hour(0-24) Day_of_month(1-31) Month(1-12) Day_of_week(0-6) Command_to_execute

1. To run a cron job at every minute, the format should be like below.

* * * * * <command-to-execute>
ex:-
* * * * * /usr/local/bin/php -q /home/user/domains/domain.com/public_html/cerb5/cron

For example if the time is 11:00, the next job will run at 11:01, 11:02, 11:03 and so on.

2. To run cron job at every 5th minute, add the following

*/5 * * * * <command-to-execute>

3. To run a cron job at every quarter hour (i.e every 15th minute), add this:

*/15 * * * * <command-to-execute>

For example if the time is 11:00, the next job will run at 11:15, 11:30, 11:45 and so on.

4.To run a cron job every hour at minute 30:

30 * * * * <command-to-execute>

For example if the time is 10:00, the next job will run at 10:30, 11:30, 12:30 and so on.

5.You can also define multiple time intervals separated by commas. For example, the following cron job will run three times every hour, at minute 0, 5 and 10:

0,5,10 * * * * <command-to-execute>

6. Run a cron job every half hour i.e at every 30th minute:

*/30 * * * * <command-to-execute>

For example if the time is now 10:00, the next job will run at 10:30, 11:00, 11:30 and so on.

7. Run a job every hour (at minute 0):

0 * * * * <command-to-execute>

For example if the time is now 10:00, the next job will run at 11:00, 12:00, 12:00 and so on.

8. Run a job every 2 hours:

0 */2 * * * <command-to-execute>

For example if the time is now 10:00, the next job will run at 12:00.
9. Run a job every day (It will run at 00:00):

0 0 * * * <command-to-execute>

10. Run a job every day at 3am:

0 3 * * * <command-to-execute>

11. Run a job every Sunday:

0 0 * * SUN <command-to-execute>
Or,
0 0 * * 0 <command-to-execute>

It will run at exactly at 00:00 on Sunday.

12. Run a job on every day-of-week from Monday through Fridayi.e every weekday:

0 0 * * 1-5 <command-to-execute>

13. Run a job every month (i.e at 00:00 on day-of-month 1):

0 0 1 * * <command-to-execute>

14. Run a job at 16:15 on day-of-month 1:

15 16 1 * * <command-to-execute>

15. Run a job at every quarter i.e on day-of-month 1 in every 3rd month:

0 0 1 */3 * <command-to-execute>

16. Run a job on a specific month at a specific time:

5 0 * 4 * <command-to-execute>

The job will start at 00:05 in April.

17. Run a job every 6 months:

0 0 1 */6 * <command-to-execute>

This cron job will start at 00:00 on day-of-month 1 in every 6th month.

18. Run a job every year:

0 0 1 1 * <command-to-execute>

This cron job will start at 00:00 on day-of-month 1 in January.

Was this article helpful?
YesNo

Leave a Reply

Your email address will not be published. Required fields are marked *