首先先跟大家介绍一下crontab
crontab安装与常用命令
1、安装
首先查看一下是否已安装crontab
which crontab
使用该命令可以查看crontab的安装位置,如果没有安装则提示不存在crontab,要执行以下命令进行安装
安装cron主程序
yum -y install vixie-cron
在安装驱动cron守护线程的表格程序
yum -y install crontabs
2、crontab常用命令
查看crontab服务状态
service crond status
查看crontab定时任务执行日志
tail -f /var/spool/mail/root
启动crontab服务
service crond start
关闭crontab服务
service crond stop
重启crontab服务
service crond restart
重新加载crontab配置
service crond reload
编辑定时任务设置
crontab -e
列出该用户的定时任务
crontab -l
删除该用户的定时任务
crontab -r
指定要设置定时任务的用户
crontab -u 用户名
crontab定时任务执行了但没有效果
排错步骤:
1、先单独运行shell脚本,确认脚本的运行结果;
2、查看crontab定时任务的执行日志,确认定时任务有执行
脚本单独运行是正确的,定时任务也正常执行,可是就是没有效果,最后发现是crontab运行要些绝对路径,crontab读取不到环境变量,将要执行的程序改成绝对路径就成功了。