centos设置定时任务

1、安装及配置

安装

dnf install cronie

启动

systemctl start crond.service

开机自启

systemctl enable crond.service

检查服务是否运行

systemctl status crond.service

2、编辑

编辑cron

crontab -e

添加任务行

例如,如果您想在每天的 2 点运行脚本,则应添加以下行:

0 2 * * * /path/to/script.sh

例如,如果您想每天 2 点钟发送一个 HTTP 请求到某个 URL 上,则应添加以下行:

0 2 * * * curl http://example.com