: # checkfs - check file system periodically # # Author: Heiner Steven # Category: System Administration # SCCS-Id.: @(#) checkfs 1.3 04/02/18 PN=`basename "$0"` Mail=mail [ -x /bin/mailx ] && Mail=/bin/mailx Admin=heiner Report="${TMPDIR:=/tmp}/checkfs.$$" trap ' [ -s "$Report" ] && $Mail -s "$PN report" $Admin < "$Report" rm -f "$Report"' 0 trap "exit 2" 1 2 3 13 15 NDirs=5 # Determine the operating system we run on OS= DF= case `uname -s` in SunOS) case `uname -r` in 4.*) OS=SUNOS DF=df DU=du ;; 5.*) OS=SOLARIS DF="df -k" DU="du -k" ;; esac;; *) echo >&2 "unknown operating system, using default commands" DF=df DU=du OS=`uname -s | tr '[a-z]' '[A-Z]'` ;; esac exec > "$Report" 2>&1 [ $# -lt 1 ] && set -- / # # Find full file systems # MinPercent=95 echo " *** File systems at least $MinPercent % full " $DF | nawk ' { if ( Header "" == "" ) Header = $0 for ( i=1; i<=NF; i++ ) { if ( $i ~ /^[0-9][0-9]*%$/ ) { Percent=$i; sub (/%$/, "", Percent) if ( Percent + 0 >= '$MinPercent' ) { if ( headerPrinted == "" ) { print Header; headerPrinted = "true" } print } } } } ' # # Find the directories consuming most space, grouped by file system # echo " *** Top $NDirs directories, grouped by file system " # Determine all file systems Filesystems= if [ -r /etc/fstab ] then # BSD/SunOS/Linux style # Example: # /dev/sd0a / 4.2 rw,quotas 1 1 exec 3<&0 0 1000' | # we are only interested in *large* directories head -$NDirs done echo " *** Hidden directories " # Find all directories and files starting with a '.' and calculate the size find "$@" \( -type d -o -type f \) -name '.*' -print | xargs $DU -s | awk '$1 > 1000' # Find all files greater than 5 MB #find "$@" -type f -size +5120 -print | xargs ls -ld