Clear Tmp Directories
In this example, we clear the tmp directories (for example, /tmp, /var/tmp, /usr/tmp, etc.) of junk and garbage files, and files more than x days old.
For the most part, the ClearTmp script removes junk files automatically and silently, but for files it is unsure of (e.g., root-owned files), it might send an alert message like the following:
PIKT ALERT
Tue Jul 15 09:51:50 2003
antwerp
NOTICE:
ClearTmp
Clear the tmp directories of garbage files
orphaned?: -rw-rw-rw- 1 root daemon 1234 Jun 28 08:26 /tmp/auth.log
orphaned?: -rw-r--r-- 1 root daemon 7336 Jun 28 08:26 /tmp/fstab.orig
ClearTmp makes reference to the =apls macro, which resolves to apls.pl, a Perl script that gives an "ls -l" listing with absolute file paths. =dirs_tmp_obj resolves to DirsTmp.obj, a list of tmp directories we want to check, for example
/tmp /var/tmp /usr/tmp ...
The script follows.
ClearTmp
init
status =piktstatus
level =piktlevel
task "Clear the tmp directories of garbage files"
input proc "=apls =dirs_tmp_obj"
filter "=grep -v '^l'" // filter out links
=lldata
rule
set #fa = #fileage($name)
rule // skip these files/directories
if $name =~ "^/tmp/(ups_data|screens|lost\\+found)"
// =execwait "=touch $name"
next
endif
rule // remove junk files 2 days old or older
if $name =~ "^/tmp/(crout|tty\\.txt|xntp[0-9]|
\\.X11-unix|\\.X11-pipe|
junk[0-9]*|\\.printd\\.lock|)"
if (#fa > 2)
=execwait "=rm -rf $name"
endif
next
endif
rule // remove all non-root stuff 7 days old or older,
// or all stuff in, for example, /var/tmp
if #fa >= 7
&& (($owner ne "root") || ($name !~ "^/tmp$"))
=execwait "=rm -rf $name"
next
fi
#if ! ( sheffield | berlin )
rule // report all root stuff older than 15 days
if #fa > 15
&& $owner eq "root"
=weekly(output mail "orphaned?: $inline", )
endif
#endif
For more examples, see Samples.