crontab定时任务执行时间与系统时间不一致解决方法

Ubuntu crontab定时任务执行时间与系统时间不一致(时区差)

查看时间

> # ll /etc/localtime

lrwxrwxrwx 1 root root 35 Aug 5 08:56 /etc/localtime -> ../usr/share/zoneinfo/Asia/Shanghai

如果不是本地时区

> # timedatectl set-timezone "Asia/Shanghai"

或者

> # cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

重启cron服务

> # service cron restart

Redirecting to /bin/systemctl restart crond.service


># date

2023年 08月 31日 星期四 15:45:22 CST


注意: Ubuntu的计划任务的服务名称cron, 而CentOS7.X系统服务名称 crond


定时任务:crontab: installing new crontab

每次写完定时任务退出之后都会有一个提示:

表示添加调度任务成功。


注意:用crontab -e 编辑的定时任务三分钟之内是不会执行的, 所以在测试的时候, 至少时间后推三分钟! 使用 service crond restart 立即生效;

举报