home *** CD-ROM | disk | FTP | other *** search
/ norge.freeshell.org (192.94.73.8) / 192.94.73.8.tar / 192.94.73.8 / pub / computers / 3b2 / lightenfs < prev    next >
Text File  |  1985-05-23  |  1KB  |  94 lines

  1. #    @(#)lightenfs    1.2    /sccs/src/cmd/sadmin/shell/s.lightenfs
  2. #    "lighten the ship" routine to clean up file systems
  3.  
  4. #!    chmod +x ${file}
  5.  
  6. set -- `getopt d:lt:v "$@"`  ||  exec $0
  7.  
  8. days=4
  9. listonly=
  10. threshold=4000
  11. verbose=
  12. for flag
  13. {
  14.     case "${flag}" in
  15.     -d )
  16.         days=$2
  17.         shift
  18.         ;;
  19.     -l )
  20.         listonly=yes
  21.         ;;
  22.     -t )
  23.         threshold=$2
  24.         shift
  25.         ;;
  26.     -v )
  27.         verbose=yes
  28.         ;;
  29.     -- )
  30.         shift
  31.         break
  32.         ;;
  33.     -* )
  34.         admerr $0 "Bad flag argument '${flag}'."
  35.         exit
  36.         ;;
  37.     * )
  38.         continue
  39.     esac
  40.     shift
  41. }
  42.  
  43. if [ $# -ne 2 ]
  44. then
  45.     echo >&2 "Usage:  $0 [-d<days>] [-t<threshold>] [-v] [-l] filesystem patternfile
  46. For more detail type:    prtdoc syscmd.`basename $0`"
  47.     exit 1
  48. fi
  49.  
  50. fs=$1
  51. patternfile=$2
  52. blocks=`expr "\`df ${fs}\`" : '.*[^0-9]\([0-9]\{1,\}\) blocks '`
  53. if [ ${blocks} -ge ${threshold} ]
  54. then
  55.     if [ ${verbose} ]
  56.     then
  57.         echo ${blocks} blocks greater than threshold ${threshold}
  58.     fi
  59.     exit 0
  60. fi
  61. if [ ${verbose} ]
  62. then
  63.     echo ${blocks} blocks free, need ${threshold}
  64. fi
  65. patterns=`sed 's/.*/\\\\;&;p/' ${patternfile}`
  66.  
  67. find ${fs} -type f -mtime +${days} -print 2>/dev/null  |
  68.     sed -n "${patterns}"  |
  69.     xargs ls -tr  |
  70.     while read f
  71.     do
  72.         if [ ${listonly} ]
  73.         then
  74.             echo ${f}
  75.             continue
  76.         fi
  77.         rm -f ${f}
  78.         blocks=`expr "\`df ${fs}\`" : '.*[^0-9]\([0-9]\{1,\}\) blocks '`
  79.         if [ ${verbose} ]
  80.         then
  81.             echo rm ${f} -- now ${blocks} blocks free
  82.         fi
  83.         if [ ${blocks} -ge ${threshold} ]
  84.         then
  85.             if [ ${verbose} ]
  86.             then
  87.                 echo Threshold met.
  88.             fi
  89.             #    swallow the rest of the ls
  90.             cat >/dev/null
  91.             exit 0
  92.         fi
  93.     done
  94.