Unaccessed files or directories in /tmp gets automatically removed by the default function of package "tmpwatch". It also cleans up the contents of directories like /var/tmp. "tmpwatch" provides a cron job /etc/cron.daily/tmpwatch which is a shell script exceuted by cron daily. This checks for the files unaccessed for a long time and removes them.

Sample configuration file on centos/RHEL5 is as below

 #  cat  /etc/cron.daily/tmpwatch

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_* '  240  /tmp

/usr/sbin/tmpwatch  "$flags"  720  /var/tmp

for  d  in  /var/ {cache/man,catman}/{cat?,X11R6/cat?,local/cat?};  do

if  [  -d  "$d"  ];  then

   /usr/sbin/tmpwatch  "$flags"  -f  720  "$d"

fi

done

Files which has been unaccessed for 240 hours (10 days for /tmp) or 720 hours (30 days for /var/tmp) will be removed from the above configuration.

Sample configuration file on CentOS/RHEL6 is as below:

#  cat  /etc/cron.daily/tmpwatch

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_* '  -X  '/tmp/ .hdblock'  -X  ' /tmp/  .sapstartsrv*.log'  \

              -X  ' /tmp/pymp-* '  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

Files/directories that have not been accessed for 10(/tmp) or 30(/var/tmp) days will be removed using the above configuration.

It is good to get the unused files removed from /tmp to free up the space. This will help the file system not to get over loaded.

However, one can disable the tmpwatch function if required, using the below methods.

1] Removing the tmpwatch package

# rpm -e tmpwatch

or

 #  yum remove tmpwatch

2] Disable the tmpwatch cron entry

In some cases, we cannot remove the tmpwatch package and will get the below error. This is because of the dependencies it has.

 #  rpm  -e  tmpwatch

LANG=C  rpm  -e  tmpwatch

error:  Failed dependencies:

tmpwatch is needed by (installed)   tetex-3.0-33.15.el5_8.1.x86_64

tmpwatch is needed by (installed)  cups-1.3.7-32.el5_11.x86_64

 

Moreover shell script /etc/cron.daily/tmpwatch can be moved or removed using the following command:

#  mv  /etc/cron.daily/tmpwatch  /other/location/tmpwatch.bkp

or

#  rm  /etc/cron.daily/tmpwatch

Disable tmpwatch only if needed as it is responsible for freeing up space.

 

 

 

 

 

 

 

 

Esta resposta foi útil? 0 Utilizadores acharam útil (0 Votos)