crontab 创建Linux 定时任务

1. 安装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. 编辑定时任务

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

3. 基础命令

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

4. 注意

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

猜你喜欢

转载自blog.csdn.net/foolere/article/details/131273906