Here is the above script, fleshed out a bit:
Code:
--------------------
#!/bin/bash
#
# spc-checkidle.sh -- bash script to check bandwidth usage on an interface
to detect an idle condition.
#
# Checking bandwidh usage on INTERFACE for CHECKDUR
duration, spc-checkidle.sh returns:
#
# 0 == below THRESHOLD; 1 == above THRESHOLD.
#
# Optional args: --interface=name # use an interface other than the
default eth0..
# --threshold=number # use a threshold other than the
default 10000 bytes..
# --duration=number # use a bandwidth check duration
other than the default 10 seconds..
# --verbose=1 # show more output..
#
# Defaults..
# Network Interface to use..
INTERFACE='eth0'
# Bandwidth threshold to check for..
THRESHOLD="10000.00"
# Duration of bandwidth check..
CHECKDUR="10"
# How chatty..
VERBOSE=0
for ARG in $*
do
OPTNAME=`echo $ARG | sed -e 's/^--\(.*\)=.*$/\1/g'`
OPT=`echo $ARG | sed -e 's/^--.*=//g'`
case ${OPTNAME} in
interface)
INTERFACE=$OPT
;;
threshold)
THRESHOLD=$OPT
;;
duration)
CHECKDUR=$OPT
;;
verbose)
VERBOSE=1
;;
*)
echo "Usage: $0 [--interface=ethN] [--threshold=NNNNN.NN] [--duration=NN]
[--verbose=N]" >&2
exit 1
esac
done
[ $VERBOSE -gt 0 ] && echo "Checking for bandwidth usage above ${THRESHOLD}
on ${INTERFACE} for ${CHECKDUR} seconds.." ;
# from wgm-ng README: csv output format, Type svg, sum, max:
#unix
timestamp;iface_name;bytes_out;bytes_in;bytes_total;packets_out;packets_in;packets_total;errors_out;errors_in\n
# Monitor bandwith usage on INTERFACE for CHECKDUR seconds | sed output just
last (total) line | awk extract the in_out_bytes_total (5th csv field)
TXSUM=`bwm-ng --interfaces ${INTERFACE} --allif 0 --type sum --unit bytes
--count ${CHECKDUR} --output csv --ansiout | sed '$!d' | awk -F ";" '{ print $5
}'`
# Check for current network bandwith usage above our THRESHOLD using bc to do
a floating point comparison..
ABOVETHRESHOLD=`echo "$TXSUM > $THRESHOLD" | bc`
if [ $ABOVETHRESHOLD -gt 0 ]
then
[ $VERBOSE -gt 0 ] && echo "System is busy! Bandwith usage on ${INTERFACE}
over ${CHECKDUR} seconds == ${TXSUM}" ;
exit 1
else
[ $VERBOSE -gt 0 ] && echo "System is not busy! Bandwith usage on
${INTERFACE} over ${CHECKDUR} seconds == ${TXSUM}" ;
fi
exit 0
--------------------
--
gharris999
------------------------------------------------------------------------
gharris999's Profile: http://forums.slimdevices.com/member.php?userid=115
View this thread: http://forums.slimdevices.com/showthread.php?t=49028
_______________________________________________
unix mailing list
[email protected]
http://lists.slimdevices.com/mailman/listinfo/unix