CentOS 7 tmpwatch 2.11 版本变更,移除 cronjob 任务

老版本(RHEL6) tmpwatch 原理

在 RHEL6 上,/tmp 目录的清理工作通常是交给 tmpwatch 程序来完成的,tmpwatch 的工作机制是通过 /etc/cron.daily/tmpwatch 定时任务脚本,每天扫描一次 /tmp 目录下的文件,进行清理工作,清理掉长时间并未访问、修改的文件。

#! /bin/sh
flags=-umc
/usr/sbin/tmpwatch "$flags" -x /tmp/.X11-unix -x /tmp/.XIM-unix 
-x /tmp/.font-unix -x /tmp/.ICE-unix -x /tmp/.Test-unix 
-X '/tmp/hsperfdata_*' 10d /tmp
/usr/sbin/tmpwatch "$flags" 30d /var/tmp
for d in /var/{cache/man,catman}/{cat?,X11R6/cat?,local/cat?}; do
    if [ -d "$d" ]; then
/usr/sbin/tmpwatch "$flags" -f 30d "$d"
    fi
done

默认定时任务脚本
排除掉特殊目录,然后对/tmp目录超过10天没有访问或修改的文件进行清理。
排除掉特殊目录,然后对/var/tmp目录超过30天没有访问或修改的文件进行清理。

新版本(RHEL7)/tmp 目录的清理工作,以及 tmpwatch 的变更

在 RHEL7 上,/tmp 目录的清理工作已经没有交由 tmpwatch 来完成了,而是通过 systemd 子程序来进行统一管理了
服务脚本路径如下:

/usr/lib/systemd/system/systemd-tmpfiles-clean.timer
/usr/lib/systemd/system/systemd-tmpfiles-clean.service

CentOS 7 上的 tmpwatch 版本 tmpwatch-2.11-6.el7.x86_64 版本变更日志:

$ sudo rpm -ql --changelog tmpwatch-2.11
* Mon Feb 11 2013 Miloslav Trmač <mitr@redhat.com> - 2.11-3
- Drop the cron.daily script, systemd default configuration handles the same
  places.
  Resolves: #906455

/usr/bin/tmpwatch
/usr/sbin/tmpwatch
/usr/share/doc/tmpwatch-2.11
/usr/share/doc/tmpwatch-2.11/AUTHORS
/usr/share/doc/tmpwatch-2.11/COPYING
/usr/share/doc/tmpwatch-2.11/ChangeLog
/usr/share/doc/tmpwatch-2.11/NEWS
/usr/share/doc/tmpwatch-2.11/README
/usr/share/man/man8/tmpwatch.8.gz

tmpwatch-2.11-3版本的时候,已经移除了 cron.daily 脚本。

原文地址:https://www.cnblogs.com/TopGear/p/13588721.html