设置周期性被执行的指令

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
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐