Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to realize the Application scenario and basic use of Crontab in Linux

Shulou Source: shulou.com Published: 2022-06-01 08:18:01 09月13日 Update

This article mainly explains "how to realize the application scene and basic use of Crontab in Linux". The content of the explanation in this article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to realize the application scenario and basic use of Crontab in Linux".

Linux version: CentOS 6.6

Application scenarios, such as:

① executes a program every minute to check the running status of the system.

② needs to do statistics on the business data of the past day in the early hours of every morning.

③ needs to back up log files every week.

④ backs up the database every month.

Crontab is a tool for setting periodic execution. The task that is executed periodically is called Cron Job, and the periodic execution list is called Cron Table.

[check crontab service]

① checks if the Crontab tool is installed:

The code is as follows:

Crontab-l

② checks whether the crontab service is started:

The code is as follows:

Service crond status

If the cron service is not installed, you can install the cron service with the following command:

The code is as follows:

Yum install vixie-cron

Yum install crontabs

Example 1. Prints the current time to a log file every minute

The code is as follows:

Corntab-e

Press O and enter:

The code is as follows:

* / 1 * date > > / tmp/log.txt

Press Esc and enter: wq! Save.

Reuse

The code is as follows:

Crontab-l

View scheduled tasks:

View the current time:

The code is as follows:

Date

View / tmp/log.txt

The code is as follows:

Tail-f / tmp/log.txt

Tail-f: keep displaying the last few lines of a file

Tail-3: displays the last three lines of a file

Thank you for your reading, the above is the content of "how to realize the application scenario and basic use of Crontab in Linux". After the study of this article, I believe you have a deeper understanding of how to realize the application scenario and basic use of Crontab in Linux. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Code scenarios applications files services checks content cycles periodicity learning tasks backups tools data logs time input continuous business commands Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Shulou Tech Info OPPO Reno Shulou Information Redmi