• news
  • pics
  • linux
  • windows
  • proxmox
  • game
  • news
  • pics
  • linux
  • windows
  • proxmox
  • game
Home
linux

crontab执行时间与系统时间不一致问题解决

前言

在LINUX中,周期执行的任务一般由cron这个守护进程来处理[ps -ef|grep cron]。cron读取一个或多个配置文件,这些配置文件中包含了命令行及其调用时间。

cron的配置文件称为“crontab”,是“cron table”的简写。

cron是一个linux下 的定时执行工具,可以在无需人工干预的情况下运行作业。

  service crond start //启动服务
  service crond stop //关闭服务
  service crond restart //重启服务
  service crond reload //重新载入配置
  service crond status //查看服务状态 

发现问题 

事情是这样的在自己的服务上有一条如下crontab

110 0 * * * root echo 'xxx' >> zzz

熟悉的人都知道是 晚上00:10执行,把xxx输出到zzz文件

可是问题来了 这条crontab不在00:10执行!而是在中午12:10执行。

crontab 执行时间和系统时间不一致!!!!

我记得服务器更改过时区现在也是 CST时区 没理由不执行啊!

试着google下crontab 时区,还真搜到 几个类似的例子

原来 修改过时间后必须手动重启crontab

1/etc/init.d/crond restart

必须重启crontab 重启服务器是没有用的,我修改时区后重启过服务器 都是没有用的,必须重启crontab!

还有一种情况的 时区分两个 一个是 timezone 还有个是localtime,按照下面命令即可解决

1
2
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
service crond restart
Previous article Failed to restart crond.service: Unit crond.service not found.
Next article shell 中 [-eq] [-ne] [-gt] [-lt] [ge] [le]

therock

1 Comment

  1. zortilonrel
    December 30, 2021 at 5:48 am

    Thanks for another informative website. Where else could I get that type of information written in such an ideal way? I’ve a project that I am just now working on, and I have been on the look out for such info.

Meta
  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
Categories
  • game
  • linux
  • news
  • pics
  • proxmox
  • windows
Recent Posts
  • proxmox7.3直通显卡
  • Proxmox VE 直通显卡方案及解决N卡Code43
  • Linux系统出现:You have new mail in /var/spool/mail/root 的原因及解决办法
  • debian系统解决中文乱码
  • pve添加git和pvetools
Recent Comments
  • EdgarTot on proxmox7.3直通显卡
  • Ashvem on proxmox7.3直通显卡
  • Tedvem on proxmox7.3直通显卡
  • Jackvem on proxmox7.3直通显卡
  • Miavem on proxmox7.3直通显卡
Archives
  • March 2023 (1)
  • December 2022 (4)
  • November 2022 (6)
  • April 2022 (1)
  • February 2022 (5)
  • January 2022 (2)
  • December 2021 (3)
  • November 2021 (1)
  • October 2021 (2)
  • September 2021 (1)
  • August 2021 (1)
  • July 2021 (8)
  • June 2021 (14)
  • May 2021 (2)
  • April 2021 (2)
  • March 2021 (10)
  • January 2021 (4)
  • December 2020 (4)
  • November 2020 (13)
  • April 2020 (276)
  • March 2020 (1)
  • June 2019 (5)
  • May 2019 (10)
  • December 2015 (1)