A script to do tmp and log directory clean up

Sep 23, '04 09:07:00AM

Contributed by: szedula

I was looking at Peter Kappesser's hint Free drive space by deleting miscellaneous excess files, but it didn't delete everything I wanted.

Read the rest of the hint to see what I came up with...

#! /bin/csh -f
#
#  tmp & log directory clean up
#
#  Settings:
#     xeq   -  0: for testing
#              1: to execute
#     old   -  how many days back are files to be deleted
#
#  Notes for "find":
#  1. -maxdepth 1 -  only looks at the current directory
#  2. -type f     -  restrict to files only
#
set xeq = 1
set old = "+7"
#
#  delete old files ending with ".gz" in /private/var/log
cd /private/var/log
echo "Checking: /private/var/log"
if ($xeq) then
  /usr/bin/find . -maxdepth 1 -type f -name "*.gz" -mtime $old -exec rm {} ;
else
  /usr/bin/find . -maxdepth 1 -type f -name "*.gz" -mtime $old -exec ls -ld {} ;
endif
#
#  delete old files from select directories
set dir_list = (/private/var/tmp /private/var/spool/cups 
                /private/var/spool/cups/tmp 
                /Library/Logs/AppleFileService 
                /Library/Logs/DirectoryService)
foreach d ($dir_list)
   echo "Checking: $d"
   cd $d
   if ($xeq) then
      /usr/bin/find . -maxdepth 1 -type f -mtime $old -exec rm {} ;
   else
      /usr/bin/find . -maxdepth 1 -type f -mtime $old -exec ls -ld {} ;
   endif
end
I've added a call to this script to /etc/weekly.local. Does anyone have suggestions for other directories that should be cleaned out on a regular basis?

Comments (4)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20040919005905173