1.如果没有就需要安装crontab
yum -y install crontabs
2.开启crontab服务
service crond start
service crond start #启动服务
service crond stop #关闭服务
service crond restart #重启服务
service crond reload #重新载入配置
# 查看crontab服务状态
service crond status
3.设置服务是否开机自启动
systemctl list-unit-files | grep crond
crond.service disabled
可以看见不是开机自启动的,所以需要设置:
systemctl enable crond.service
systemctl list-unit-files | grep crond
crond.service enabled
结果如上就设置好了。
4.设置需要执行的脚本
crontab -e
按上面的格式编辑文本,如:
0 2 * * * /root/test.sh
表示在每天2点执行root目录下的test.sh脚本