PIKT

Samples: Clear Tmp Directories

PIKT Logo
Home FAQ News Intro Samples Tutorial Reference Software Authors Licensing SiteSearch


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 (not shown) 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.

///////////////////////////////////////////////////////////////////////////////
//
// disks_alarms.cfg
//
///////////////////////////////////////////////////////////////////////////////

[other alarms omitted...]

///////////////////////////////////////////////////////////////////////////////

ClearTmp

        init
                status active
                level notice
                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($mon,$date,$time)

        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"
                                if #fa % 7 == 0 // report only every 7 days
                                        output mail "orphaned?: $inline"
                                endif
                endif
#endif

///////////////////////////////////////////////////////////////////////////////

[other alarms omitted...]

///////////////////////////////////////////////////////////////////////////////

[For more examples, see Samples.]


Home | FAQ | News | Intro | Samples | Tutorial | Reference | Software | Authors | Licensing | SiteSearch
Links | SiteIndex | Pikt-Users | Pikt-Workers | Contribute | ContactUs | Top of Page
Page best viewed at 1024x768.   Page last updated 2005-06-22.
This site is PIKT® powered.
PIKT® is a registered trademark of the University of Chicago.
Copyright © 1998-2005 Robert Osterlund.  All rights reserved.

Computer Books at Amazon.com

Essential CVS
Essential CVS

Performance Tuning for Linux Servers
Performance Tuning for Linux Servers

From Bash to Z Shell: Conquering the Command Line
From Bash to Z Shell: Conquering the Command Line

The Linux Enterprise Cluster
The Linux Enterprise Cluster

CVS Pocket Reference
CVS Pocket Reference