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

Use the crontab command of linux to perform tasks regularly

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article mainly introduces the use of linux crontab command to regularly execute tasks, the article is very detailed, has a certain reference value, interested friends must read it!

Crontab is the abbreviation of "cron table". This command is used to submit and manage the tasks that users need to execute periodically, similar to the scheduled tasks under windows. When the operating system is installed, the service tool is installed by default, and the crond process is automatically started. The crond process periodically checks whether there is a task to be executed every minute, and automatically executes the task if there is a task to be executed.

Task scheduling under Linux is divided into two categories: system task scheduling and user task scheduling.

System task scheduling: the work that the system periodically performs, such as writing cached data to the hard disk, log cleaning, etc. The / etc/crontab file is the configuration file for system task scheduling. User task scheduling: tasks that users perform on a regular basis, such as user data backup, scheduled email reminders, etc. Users can use the crontab tool to customize their scheduled tasks. All user-defined crontab files are saved in the / var/spool/cron directory. Its file name is the same as the user name.

Syntax format: crontab [parameters]

Common parameters:

-e Edit the user's timer settings-l list the user's timer settings-r delete the user's timer settings-u specify the user name to set the timer-help display help information

Reference example

Create and edit scheduled tasks:

[root@linuxcool] # crontab-e

View the current scheduled task:

[root@linuxcool ~] # crontab-l

Delete a scheduled task:

[root@linuxcool ~] # crontab-r

Before formally deploying the scheduled task, let's take a look at the parameter format for the task using the crond service (note that if some fields are not set, you need to use an asterisk (*) to occupy the place):

Minute hour day month week command order: time-sharing, day, month and week command

Use crond to set the parameter field description for the task:

Minute represents minutes, any integer from 0 to 59 hour represents hours, any integer from 0 to 23 day represents the date, any integer from 1 to 31 month represents the month, any integer week from 1 to 12 represents the week, any integer from 0 to 7, where 0 or 7 represents the command to be executed by Sunday command, which can be a system command or a script file written by yourself

At 03:25 every Monday, Wednesday and Friday, use the tar command to package the data directory of a website as a backup file. We use the crontab-e command to create scheduled tasks. You do not need to use the-u parameter to create a scheduled task for yourself. The specific parameters to achieve the effect are shown in the result of the crontab-l command:

[root@linuxcool ~] # crontab-e no crontab for root-using an empty one crontab: installing new crontab [root@linuxcool ~] # crontab-l 25 3 * * 3Power3 / usr/bin/tar-czvf backup.tar.gz / home/wwwroot above is all the contents of using linux's crontab command to execute the task regularly, thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

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: 0

*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

Servers

Wechat

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

12
Report