SCRIPT BASH monitor big files
Lars Stavholm
stava at telcotec.se
Wed Sep 5 18:22:40 CEST 2007
riky.none wrote:
> I need one script BASH that looking for all files big more xx
> in ML there is one god BASH programmer??? >:)
>
> syntax check_file_size volume MAX MB (es. check_file_size /home 400)
> output
> OK no big file
> ERROR there is file1 file2 file3 > of MAX
>
> i have create one but is terrible ed not work
>
> why BASH????
> because i can not install sw in HPUX e LINUX machine (i use ssh to run
> remote command)
> bye
Maybe this will help:
--- Begin Included Message ---
check_file_size.sh:
#!/bin/bash
# @(#) $Id$
# @(#) Check file sizes using find(1) and alert if out of bounds.
# preliminaries...
pgm=`basename $0`
ver=`echo '$Revision: 1.0 $' | sed -e 's/[^0-9.]//g'`
dir="/home"; wsize="20M"; csize="50M"
usg="usage: $pgm [-h,--help] [-V,--version] [-g, --debug]
[{-w,--warning} <size>] [{-c,--critical} <size>] [<dir>]
Scan <dir> for file sizes using find(1) and issue a...
o warning if size is between -w <size> and -c <size>, or a...
o critical if bigger than -c <size>, or...
o OK if no files bigger than -w <size> were found.
-h, --help this text, no other action
-V, --version display verion, no other action
-g, --debug turn on debug mode
-w, --warning <size> warning file size, default $wsize
-c, --critical <size> critical file size, default $csize
<dir> directory to scan, default $dir"
# Nagios states...
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
# error handling...
err()
{
echo >&2 "$pgm: $*"
exit $STATE_UNKNOWN
}
# get and validate inpt options...
args=`getopt -o hVgw:c: \
-l help,version,debug,warning:,critical: \
-u -n$0 -- "$@"`
[ $? = 0 ] || err "aborted"
set -- $args
# parse input options...
while true; do
case $1 in
-h|--help) echo "$usg"; exit $STATE_OK;;
-V|--version) echo "$pgm version $ver"; exit $STATE_OK;;
-g|--debug) set -x; shift;;
-w|--warning) wsize=$2; shift 2;;
-c|--critical) csize=$2; shift 2;;
--) shift; break;;
*) err "internal error";;
esac
done
# get the last item, if there at all...
[ -n "$*" ] && dir="$*"
# validate directory exists...
[ -d $dir ] || err "$dir: not found"
# prepare...
xargs="xargs -r ls -lh"
awk="awk '{print \$3,\$5,\$9}'"
state=$STATE_OK
# look for warnings...
find="find $dir -warn -size +$wsize -a -size -$csize"
warn=`$find | $xargs | eval $awk`
[ -n "$warn" ] && state=$STATE_WARNING && wcount=`$find | wc -l`
# look for critical...
find="find $dir -size +$csize"
crit=`$find | $xargs | eval $awk`
[ -n "$crit" ] && state=$STATE_CRITICAL && ccount=`$find | wc -l`
# display some output...
case $state in
$STATE_OK) echo "File size check OK - no files matched criteria";;
$STATE_WARNING) echo "Warning: $wcount files matched criteria - $warn";;
$STATE_CRITICAL) echo "Critical: $ccount files matched criteria - $crit";;
esac
# exit with proper state...
exit $state
--- End Included Message ---
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue.
::: Messages without supporting info will risk being sent to /dev/null
More information about the Users
mailing list