#$Id: chkdf,v 1.71 2025/01/19 14:34:51 fulford Exp $ #$Source: /src/admin/usr/local/etc/RCS/chkdf,v $ #$Author: fulford $ #$Revision: 1.71 $ # # Copyright (c) 2012-2015 Clifford W Fulford. # Licensed for public use under the LGPL. # For assistance call 0709 229 5385 # e-mail fulford@fulford.net ######################################################################## cmd=`basename $0` syntax="$0 [-c <config file> [-e <email_rcpt>] [-l] [-m #(max % used)] [-u <login] [-v] [host]" while [ $# -gt 0 ];do case $1 in -c) config=$2;shift 2;; -d) debug=:;adebug="-v debug=1";set -x;shift;; -e) rcpt=$2;shift 2;; -u) login=$2;shift 2;; -l) log=:;shift;; -m) max=$2;shift 2 ;; -v) verbose=:;shift ;; -[^cvmru]) echo $syntax >&2 ; exit;; *) host=$1;shift;; esac done config=${config:="/usr/local/etc/chkdf.cf"} default=60 host=${host:=localhost} login=${login:=`id -nu`} logger="/usr/bin/logger" max=${max:-0} msg=/tmp/${cmd}msg$$ tmp=/tmp/$cmd${host}$$ hdf=/tmp/$cmd${host}hdf$$ verbose=${verbose:-""} [ $log ] && { $logger -t $cmd "$host run" ;} if [ -f $config ];then if ! grep $host $config >/dev/null;then echo "$cmd: no configuration for $host, using defaults." >&2 fi sed -ne '/^'$host':/,/^$/{ /^[ \t].*:.*/{ s/\t// s/:/ / p } }' $config >$tmp [ $max -gt 0 ] && echo "max $max" >>$tmp grep default $tmp >/dev/null||{ echo "default $default">>$tmp } else echo "$cmd: config $config not found" >&2 exit 1 fi rcpt=${rcpt:=`id -nu`} [ $verbose ] && echo "`basename $0`: contacting $host" >&2 if [[ $(hostname) =~ $host ]];then df -lPk else ssh -l $login $host "df -lPk" fi| sed -e '/\/dev\/loop/d;/\/dev\/sr/d'>$hdf awk $adebug -v host=$host -v cmd=$cmd '{ if(NR == FNR) { a[$1]=$2 } if(NR > FNR){ if($1 !~ /Filesystem/){ sub("%","",$5); if("max" in a){ max=a["max"] }else{ if($6 in a) max=a[$6] else max=a["default"] } # $5 not converting to numeric properly force # by adding zero. if ($5 + 0 > max){ printf "Warning! %6s %3d%% on %s\n",$6,$5,host } } } }' $tmp $hdf | while read line;do echo "$line" >>$msg [ $log ] && logger -t $cmd "$line" [ $verbose ] && echo "$cmd: $line" done [ $verbose ] &&{ if [ ! -f $msg ];then echo "$cmd: $host ok" fi } if [ -f $msg ];then mailx -s "$cmd $host warning! `date`" ${cc:+"-c $cc"} $rcpt <$msg rm $msg fi [ "$debug" ] && { cat $tmp $hdf ;} rm $tmp $hdf ###################################################################### # This program is free software: you can redistribute it and or # # modify it under the terms of the Lesser GNU General Public License # # as published by the Free Software Foundation, either version 3 of # # the License, or (at your option) any later version. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # A copy of the Lesser GNU General Public License and the GNU # # General Public License is available at # # <http://www.gnu.org/licenses/>. # ######################################################################
Copyright
© 2003-2017
Clifford W Fulford.
Fulford Consulting Ltd.
Regd. Co. 4250037 in England & Wales.
Regd. office 162, Edward Rd. Nottingham NG2 5GF, England, UK.
Related web sites: City Linux | Flare Support | West Bridgford | Fulford Portal | Joan Mary Fulford (Nottingham Writer) | Fulford Gallery | Amharic Interpreter | Arabic Interpreter | Tigrinya Interpreter
The layout and associated style sheets for this page are taken from the World Wide Web Consortium and used here under the W3C software licence.