Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 17 Dec 2008 13:53:53 -0500 (EST)
From:      vogelke+software@pobox.com (Karl Vogel)
To:        freebsd-questions@freebsd.org
Subject:   Re: How to find files that are eating up disk space
Message-ID:  <20081217185356.25025B7BA@kev.msw.wpafb.af.mil>
In-Reply-To: <283ACBF4-8227-4A24-9E17-80A17CA2A098@identry.com> (message from John Almberg on Wed, 17 Dec 2008 12:16:57 -0500)

next in thread | previous in thread | raw e-mail | index | archive | help
>> On Wed, 17 Dec 2008 12:16:57 -0500, 
>> John Almberg <jalmberg@identry.com> said:

J> Is there a command line tool that will help me figure out where the [disk
J> space] problem is?

   I run a script every night to handle this.  We have a few business
   divisions, and each division has several groups sharing files
   via Samba.  Each group likes its own space with permissions that
   prevent file diddling by other groups.  For example, division 3 is
   on drive /rd04, and has group directories /rd04/div3/engineering,
   /rd04/div3/finance, and /rd04/div3/marketing.

   /etc/periodic/daily/315.dirsize:

      #!/bin/ksh
      # dirsize: see how big each top-level group directory is.

      PATH=/bin:/usr/bin
      BLOCKSIZE=1m
      BLOCK_SIZE=1048576
      export PATH BLOCKSIZE BLOCK_SIZE

      umask 022
      tag=`basename $0`
      host=`hostname | cut -f1 -d.`

      logmsg () {
          logger -t "$tag" "$@"
      }

      # Check group areas on each drive.

      list='
      /rd01/div1
      /rd02/logs
      /rd03/div2
      /rd04/div3
      '

      (
          for dir in $list
          do
              logmsg checking size of $dir
              find $dir -type d -maxdepth 1 -print |
                  tail +2 | sort | xargs du -s
              echo
          done

      ) | mailx -s "$tag: directory sizes on $host" root

      logmsg done
      exit 0

J> Even better, is there a way to proactively monitor the file system, so I
J> can fix problems before I start getting 'out of disk space' errors?

   This script is run hourly to tell me if we completely run out of room
   on something like /var or one of the user drives.  I run it on BSD and
   Solaris boxes, so I try to avoid GNU or OS dependencies.

   /usr/local/cron/checkdrives:

      #!/bin/ksh
      # checkdrives: send mail if a filesystem gets too full

      PATH=/bin:/usr/bin
      export PATH

      # Portability stuff here.

      case "`uname -s`" in
          SunOS)    DF='/usr/xpg4/bin/df -F ufs -k' ;;
          FreeBSD)  DF='/bin/df -t ufs -k' ;;
          *)        DF='df' ;;
      esac

      # "Too full" means 99% and less than 100 Mbytes available.

      str=`$DF |                      # Check filesystem size ...
        tail +2 |                     # ... skip the header ...
        tr -d '%' |                   # ... kill the percent sign ...
        awk '$4 < 100000 && \
             $5 >= 99 {print $6}'`    # ... and print the filesystem.

      case "X$str" in
          X)  ;;
          *)  $DF $str | mailx -s 'Filesystem getting full' root ;;
      esac

      exit 0
      
-- 
Karl Vogel                      I don't speak for the USAF or my company
It only rains straight down.  God doesn't do windows.   --Steven Wright



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20081217185356.25025B7BA>