Learn cronjob configuration parameters

Tram Ho

Just now, I had a task to do a scheduler to clear junk data, run once a month. Before I run cronjob with the server’s support tool, there is UI so I don’t care what mechanism it configures, just bury right-day-month-year-hour-minute-second in the right box, click OK and it is automatically generate configuration.

However this time I have to touch the configuration for cronjob. Convenient to learn it should note a post

Cronjob configuration structure

Cronjob usually takes the form


For 5 characters, it is:

For 6 characters, add a second:

The X characters are replaced by one of the following:

First glance at this pile, I suddenly thought: easy vkl. Now want to test for it to run every 2 seconds to test the scheduler then buried config

There is no difficult mother: v. However, when running the test, it was wrong. It runs 1 minute 1 time. That’s the second second of every minute , not every 2 seconds. Thus, the configuration of cron must be exactly:

Config 2s 1 times what type?

Let’s take a look at the alternate characters of X, we can configure to run every 2 seconds using the following methods:

Use “,”

The “,” symbol represents the list of values. This means that if you want to run every 2 seconds, you list the second values ​​that appear every second.

This method is quite manual, should only be used when you use to configure a few special values, there are no rules.

Use “-“

The “-” sign represents a value range. For example, if you want to run at seconds 1,2,3,4,5,6, you can use “-” for brevity, instead of “,”. That is:

Of course, this config cannot be used for 2s at a time. By the way, I recommend it

Use “/”

The “/” symbol represents the jump of the value, calculated from 0. Assuming the character at the position of seconds, I configured:

You can also change the * symbol as the starting position of the jump. For example

However, this is a “non-standard config”, which is not a standard config so it may not work on some cronjob systems.

Thus, to config 2s / times, the “redundant” config:

Create cronjob online

There are several websites that allow you to create cronjob online, including explanations. It is easy to understand. I use the following two pages:

  1. https://crontab.guru/
  2. http://www.cronmaker.com/

If there is anything wrong or not optimal in the post, please comment let me know ^^ Thanks for reading ^^

Source of articles from my blog: https://minhphong306.wordpress.com/2018/09/03/tutorial-tim-hieu-cac-thong-so-cau-hinh-cronjob/

Share the news now

Source : Viblo