Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Linux timer cron

Shulou Source: shulou.com Published: 2022-06-01 15:07:55 11月12日 Update

This article will explain in detail how to use Linux timer cron for you. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

Crond is a daemon used under linux to periodically execute certain tasks or wait for certain events to be handled. Similar to the scheduled tasks under windows, when the installation of the operating system is completed, this service tool will be installed by default, and the crond process will be started automatically.

Img creates a cronjob

To create a cronjob, you can use the crontab command and add the-e option:

$crontab-e

This opens crontab using the default text editor. To specify a text editor, use the EDITOR environment variable:

$EDITOR=nano crontab-eCron syntax

To schedule a cronjob, you need to provide the computer with the command you want to execute, and then provide an cron expression. The cron expression runs when the command is scheduled:

Minutes (0 to 59)

Hours (0 to 23, 0 for midnight)

Date (1 to 31)

Month (1 to 12)

Week (0 to 6, Sunday is 0)

The asterisk (*) stands for "each". For example, the following expression runs the backup script at 0 minutes per hour every day of each month:

/ opt/backup.sh 0 *

The following expression runs the backup script at 3:30 on Sunday:

/ opt/backup.sh 30 3 * * 0 abbreviated syntax

Modern cron supports simplified macros instead of cron expressions:

@ hourly runs at 0 minutes every hour every day

@ daily runs at 00:00 every day

@ weekly runs at 00:00 on Sunday

@ monthly runs at 00:00 on the first day of each month

For example, the following crontab command runs the backup script at 0 every day:

/ opt/backup.sh @ daily

How to stop a cronjob

Once you start a cronjob, it will always run as planned. To stop cronjob after startup, you must edit crontab, delete the command line that triggered the job, and then save the file.

$EDITOR=nano crontab-e

To stop a running job, you can use the standard Linux process command to stop a running process.

It's automatic.

Once you have finished writing the crontab, save the file and exit the editor. Your cronjob has been scheduled, and the rest of the work is left to cron.

This is the end of the article on "how to use Linux timer cron". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Tags: Run command expression process backup hour article editor script face-to-face scheduling timer representative task file text week more being syntax Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Linux Shulou Tech Info Shulou Information macOS