格 千格 KiloCell

Crontab generator

Visualise Linux Cron Timed Job Expression

* * * * *
Do it every minute.
Common Templates
Every minute
* * * * *
Hourly
0 * * * *
Every night at midnight.
0 0 * * *
Working day 9 am
0 9 * * 1-5
Every 5 Minutes
*/5 * * * *
1 per month
0 0 1 * *
Next time to execute

    Crontab Timed Mandate Full Guide: From Introduction to Resolution of Practical Problems

    In the Linux system management and automated transport, the government has been able to provide the necessary information to the people. Crontab It is an indispensable tool. It allows users to execute scripts or commands at certain times or intervals, thus enabling automatic backup, log clean-up, data synchronization, etc.

    What is the Cron expression?

    Cron expression is by 5 or 6 string of a field, each field represents a unit of time. The standard Crontab expression generated by this tool contains 5 Fields:

    • min (0 - 59)
    • Hours (0 - 23)
    • Date (1 - 31)
    • Month (1 - 12)
    • Week (0 - 6,0 代表Sunday)

    2. Common problems and solutions

    Scenario one: How do you set up to perform the task every five minutes?

    In development, we often need to run some check scripts at high frequencies. Use step longcards / It can be easily achieved. Solutions: Set the minute field to */5 , the rest of the field is * 。 Expression is: */5 * * * * 。

    Scenario 2: How do you configure the task by just running it on a working day?

    In order to save server resources, some business scripts may only be available on Mondays to Fridays. Solutions: Set the weekly field to 1-5 。 For example, running at 9 a.m. every morning: 0 9 * * 1-5 。

    Scenario III: How to deal with multiple specific points of time?

    If you want to run backups at 2 a.m., 12 p.m. and 8 p.m. each day. Solutions: Comma , Splits multiple values. Set hour field to 2,12,20 。 Expression is: 0 2,12,20 * * * 。

    Crontab Small Skills

    • Environmental variables: Cron runs different environment variables than login Shell, and suggests absolute paths for scripts.
    • Redirect log: Use >> /var/log/mycron.log 2>&1 Records both errors and outputs in the document to facilitate the referencing of problems.
    • Permission check: Ensure that the executed script has enforceable authority ( chmod +x script.sh )。

    Use ours. Online Crontab Generator , you can preview the meaning of the expression in real time and the time of execution, and you can avoid the grammatical error of manually writing the expression.