Home > Article > System Tutorial > CentOS installation Crond: teach you step by step to set up scheduled tasks
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!
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.
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.
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!