#! /bin/bash # ############################################################################# NAME_="lowstorage" PURPOSE_="notify when space on any storage device is less then n Megabytes" SYNOPSIS_="$NAME_ [-hl] [device..]" REQUIRES_="standard GNU commands, xmessage" VERSION_="1.4" DATE_="1999-08-10; last update: 2004-12-09" AUTHOR_="Dawid Michalczyk " URL_="www.comp.eonworks.com" CATEGORY_="admin" PLATFORM_="Linux" SHELL_="bash" DISTRIBUTE_="yes" # ############################################################################# # This program is distributed under the terms of the GNU General Public License usage () { echo >&2 "$NAME_ $VERSION_ - $PURPOSE_ Usage: $SYNOPSIS_ Requires: $REQUIRES_ Options: , an integer referring to Mb [device], full path to the device(s) to exclude, eg: /dev/cdrom -h, usage and options (this help) -l, see this script" exit 2 } # tmp file set up tmp_1=/tmp/tmp.${RANDOM}$$ tmp_2=/tmp/tmp.${RANDOM}$$ tmp_3=/tmp/tmp.${RANDOM}$$ # signal trapping and tmp file removal trap 'rm -f $tmp_1 $tmp_2 $tmp_3 >/dev/null 2>&1' 0 trap "exit 2" 1 2 3 15 # enabling extended globbing shopt -s extglob # option handling case $1 in -h) usage ;; -l) more $0; exit 2 ;; +([0-9])) # arg1 can only be an integer mb=$1 shift while :;do if [[ $@ ]];then df -m | sed '1d' > $tmp_1 for a in $@;do echo $a | sed 's-\/-\\/-g' >> $tmp_2 done sed -e 's-^-/-g' -e 's-$-/d-' $tmp_2 > $tmp_3 sed -f $tmp_3 $tmp_1 > $tmp_2 else df -m | sed '1d' > $tmp_2 fi while read dev blocks used free perc mounted;do if (( $free < $mb ));then # display windowed message if x is running; ring a bell ps -aux | grep -q xinit if [ $? = 0 ];then echo -en \\a xmessage -center Device $dev mounted on \ $mounted is running low on space! Only ${free}Mb left. exit 0 else # write message to terminal and ring a bell echo -e \\a Device $dev mounted on $mounted is running \ low on space! Only ${free}Mb left. exit 0 fi fi done < $tmp_2 rm -f $tmp_2 sleep 60s # how often to check disk done ;; *) echo invalid argument, type $NAME_ -h for help ; exit 2 ;; esac