crontab creates Linux scheduled tasks

1. Install crontab

# 检查是否安装
crontab -e
# 安装
yum -y install vixie-cron
yum -y install crontabs
说明:
vixie-cron软件包是crontab的主程序
crontabs软件包是用来安装、卸装、或列举用来驱动crontab守护进程的表格的程序
# 启动
systemctl start crond.service
# 开机自启动
systemctl enable crond.service

2. Edit scheduled tasks

touch crond.sh
chmod +x crond.sh
vi crond.sh
添加如下内容:
 
#! /bin/sh
#每天早上9点重启httpd服务
* 09 * * * systemctl restart httpd
 
#重启crontab
systemctl restart crond.service

3. Basic commands

crontab -e 编辑定时任务
crontab -l 列出定时任务
crontab -r 清空定时任务

4. Attention

1、当需要使用sh文件时,文件内容必须有
#! /bin/bash
2、必须给sh文件授予可执行权限
chmod +x xxx.sh

Guess you like

Origin blog.csdn.net/foolere/article/details/131273906