Home > System Tutorial > LINUX > CentOS installation Crond: teach you step by step to set up scheduled tasks

CentOS installation Crond: teach you step by step to set up scheduled tasks

PHPz
Release: 2024-02-12 23:12:18
forward
1206 people have browsed it

php editor Zimo will introduce you how to install Crond in CentOS system, and teach you step by step to set up scheduled tasks. Crond is a very useful tool that can help us perform specific tasks at a specified time, such as backing up data, sending emails at scheduled times, etc. Through the guidance of this article, you will learn how to install Crond and set up scheduled tasks to make your work more efficient and automated. Follow the editor to explore together!

CentOS 安装 Crond:一步步教你设置定时任务

1. Install Crond

In the CentOS system, we can use the yum command to install the Crond service, open the terminal, and execute the following command as the root user :

```shell

sudo yum install cronie

```

After the installation is completed, the Crond service will start automatically.

2. Configure Crond

Crond’s configuration file is located in /etc/crontab. We can use any text editor to open the file for configuration.

```bash

sudo nano /etc/crontab

In the configuration file, we need to define the execution time of the scheduled task and the command to be executed, Crond time The format is as follows:

```lua

* * * * * command to be executed

- - - - -

| | | | |

| | | | ----- day of the week (0 - 6) (Sunday=0)

| | | ------- month (1 - 12 )

| | ---------- day of the month (1 - 31)

| ---------- hour (0 - 23 )

------------- min (0 - 59)

For example, if we want to automatically back up the database at 12 o'clock every night, we can add The following configuration:

```javascript

0 0 * * * /usr/bin/mysqldump -u username -p password database_name > /path/to/backup.sql

The commands here need to use absolute paths.

3. Start and stop the Crond service

We can use the following command to start and stop the Crond service:

sudo systemctl start crond #Start the service

sudo systemctl stop crond # Stop the service

sudo systemctl status crond #View the service status

The above is the detailed content of CentOS installation Crond: teach you step by step to set up scheduled tasks. For more information, please follow other related articles on the PHP Chinese website!

source:xiaosiseo.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template