Source

w3 / contrib / clean-cache

#!/bin/sh
#
# Copyright Š 1995-1997, William M. Perry <wmperry@aventail.com>
#
# Author:	William M. Perry <wmperry@aventail.com>
# Maintainer:	William M. Perry <wmperry@aventail.com>
# Created:	95/04/18 10:44:15
# Version:	1.1.1.1
# Modified:     1998/12/01 22:11:57
# Keywords:	cache clean
# 
# This shell script will clean out your cache directory for Emacs/W3
# It is designed to be run from a cron (see crontab(5)) or at(1) job.
#
# This should probably only be run occasionally: like once a month, or
# when you determine that the cache size is too big.  Something like:
#
# CACHEMAXSIZE=5000
# SIZE=`du -s $CACHE_ROOT | awk '{print $1}'
# if [ $SIZE -gt $CACHEMAXSIZE ] ; then
#   /run/the/real/clean-cache
# fi

if [ -z "$CACHE_ROOT" ] ; then
  CACHE_ROOT=/tmp/$USER			# The root directory of the cache
fi

if [ -z "$CONTROL_FILE" ] ; then
  CONTROL_FILE="$CACHE_ROOT/.clean"
fi

if [ -z "$CLEAN_PROTOCOLS" ] ; then
  CLEAN_PROTOCOLS="http gopher file ftp wais news"
fi

if [ -f "$CONTROL_FILE" ] ; then
  echo "Starting to clean $CACHE_ROOT..." `date`

  for x in $CLEAN_PROTOCOLS
  do
    if [ -d "${CACHE_ROOT}/${x}" ] ; then
      echo "  Cleaning $x files"
      find $CACHE_ROOT/$x -depth -type f \( ! -anewer "$CONTROL_FILE" \) \
       -exec rm -f {} \;
      find $CACHE_ROOT/$x -depth -type d -exec rmdir {} \;
    fi
  done
  
  touch "$CONTROL_FILE"
  echo "Cache clean ended: "`date`
else
  echo "The cleaning control file ($CONTROL_FILE) could not be found."
  echo "To create it (and make all your cache files 'current' do:"
  echo ""
  echo "touch $CONTROL_FILE"
  echo "find $CACHE_ROOT -exec touch {} \;"
  echo ""
  echo "PLEASE NOTE: This can damage your cache, by changing the times it"
  echo "sends to the remote server to see if the file was modified."
  echo "I recommend just touching the file, then rerunning this script to"
  echo "wipe the cache clean and start over."
fi