我一直在使用 kSar 来查看我的服务器资源使用情况。每天凌晨 4 点 04 分,进程创建量明显激增。Cron 似乎定义了它们应该运行的间隔,但没有定义具体的时间
我怎样才能找到当时运行的 cron 作业?
如果您查看任何 CentOS 5 或 6 系统,该文件/etc/crontab通常是所有操作开始的地方。有 4 个目录将包含各种脚本。这些目录被命名为:
$ ls -1d /etc/cron*
/etc/cron.d
/etc/cron.daily
/etc/cron.deny
/etc/cron.hourly
/etc/cron.monthly
/etc/crontab
/etc/cron.weekly
Run Code Online (Sandbox Code Playgroud)
该/etc/cron.d和/etc/cron.deny特殊,所以我不打算讨论这些问题。剩下的 4 个目录:每小时、每天、每周和每月,正如它们的名字所暗示的那样。但是他们什么时候跑?看一看/etc/crontab就知道了。
######################################################################
## run-parts
##
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
######################################################################
Run Code Online (Sandbox Code Playgroud)
您每天凌晨 4:04 运行的问题?这是/etc/cron.daily导致这种情况的目录。您需要熟悉该目录中的内容才能知道真正的罪魁祸首是什么。但如果我不得不猜测它很可能是这两个人之一:
$ ls -l /etc/cron.daily
logrotate
mlocate.cron
Run Code Online (Sandbox Code Playgroud)
如果您有一个异常的 cron 使您的系统崩溃,请务必查阅日志文件。这是在我的 CentOS 5 系统上凌晨 4 点运行的所有内容:
$ grep " 04:" /var/log/cron | head -10
Feb 9 04:10:01 skinner crond[25640]: (root) CMD (/usr/lib/sa/sa1 1 1)
Feb 9 04:20:02 skinner crond[27086]: (root) CMD (/usr/lib/sa/sa1 1 1)
Feb 9 04:22:01 skinner crond[27432]: (root) CMD (run-parts /etc/cron.weekly)
Feb 9 04:22:01 skinner anacron[27436]: Updated timestamp for job `cron.weekly' to 2014-02-09
Feb 9 04:30:01 skinner crond[28561]: (root) CMD (/usr/lib/sa/sa1 1 1)
Feb 9 04:40:01 skinner crond[30022]: (root) CMD (/usr/lib/sa/sa1 1 1)
Feb 9 04:50:01 skinner crond[31482]: (root) CMD (/usr/lib/sa/sa1 1 1)
Feb 10 04:00:02 skinner crond[7578]: (root) CMD (/usr/lib/sa/sa1 1 1)
Feb 10 04:01:01 skinner crond[7700]: (root) CMD (run-parts /etc/cron.hourly)
Feb 10 04:02:01 skinner crond[7934]: (root) CMD (run-parts /etc/cron.daily)
Run Code Online (Sandbox Code Playgroud)
注意到 04:02 AM 的时间段了吗?