From owner-freebsd-questions@FreeBSD.ORG Wed Dec 17 19:18:55 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 435341065674 for ; Wed, 17 Dec 2008 19:18:55 +0000 (UTC) (envelope-from SRS0=va4oVo=4W=shell.siscom.net=vogelke@siscom.net) Received: from lamorack.siscom.net (lamorack.siscom.net [209.251.2.116]) by mx1.freebsd.org (Postfix) with ESMTP id F30498FC12 for ; Wed, 17 Dec 2008 19:18:54 +0000 (UTC) (envelope-from SRS0=va4oVo=4W=shell.siscom.net=vogelke@siscom.net) Received: from shell.siscom.net ([209.251.2.80]) by lamorack.siscom.net with esmtp (Exim 4.62) (envelope-from ) id 1LD1YH-0000tv-AE for freebsd-questions@freebsd.org; Wed, 17 Dec 2008 13:55:21 -0500 Received: by shell.siscom.net (Postfix, from userid 2198) id 266C6115529; Wed, 17 Dec 2008 13:55:21 -0500 (EST) Received: by kev.msw.wpafb.af.mil (Postfix, from userid 32768) id 25025B7BA; Wed, 17 Dec 2008 13:53:53 -0500 (EST) To: freebsd-questions@freebsd.org In-reply-to: <283ACBF4-8227-4A24-9E17-80A17CA2A098@identry.com> (message from John Almberg on Wed, 17 Dec 2008 12:16:57 -0500) Organization: Oasis Systems Inc. X-Disclaimer: I don't speak for the USAF or Oasis. X-GPG-ID: 1024D/711752A0 2006-06-27 Karl Vogel X-GPG-Fingerprint: 56EB 6DBF 4224 C953 F417 CC99 4C7C 7D46 7117 52A0 Message-Id: <20081217185356.25025B7BA@kev.msw.wpafb.af.mil> Date: Wed, 17 Dec 2008 13:53:53 -0500 (EST) From: vogelke+software@pobox.com (Karl Vogel) Subject: Re: How to find files that are eating up disk space X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: vogelke+software@pobox.com List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Dec 2008 19:18:55 -0000 >> On Wed, 17 Dec 2008 12:16:57 -0500, >> John Almberg 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