#! /bin/sh # ckspace (Bourne shell script) -- report if any filesystem's free space is too low # Version 1.0 # # Copyright (C) 2012 Alastair Irvine # Warpspace IT # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # On Debian systems, the complete text of the GNU General Public License # can be found in `/usr/share/common-licenses/GPL'. # # # TO-DO: support Darwin df_opts="-k" threshold=75 # df's output is wrapped sometimes, so merge each filesystem's output onto one line merge_lines () { # if there is a line with just one field, then it is a long device name # so save it and print this device field at the start of the next line awk 'NF > 1 { # this line might hold everything but the device # (if the device was too long it was on the previous line) if (stashed_dev) { print stashed_dev " " $0; stashed_dev=0; } else print $0; } NF == 1 { # this line holds just a long device name stashed_dev=$1 }' } # *** MAINLINE *** case `uname -s` in Darwin) echo MacOS X not supported >&2 exit 3 ;; FreeBSD) df_opts="$df_opts -t ufs" ;; Linux) df_opts="$df_opts -l -x tmpfs" ;; Solaris) df_opts="$df_opts -l" ;; *) echo Unix release `uname -s` not supported >&2 exit 3 esac # run df and iterate over the mount points df $df_opts | merge_lines | while read dev size used avail capacity mount_point ; do if [ $dev = Filesystem ] ; then continue fi # remove the first percent character and everything after it percent_used=${capacity%%%} # check the usage of this mount point if [ $percent_used -gt $threshold ] ; then echo $mount_point is $capacity used! fi done