Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Linux timer cron

2025-04-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 242

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report