这里有个类似的例子,大家看看
#!/bin/sh
#
# External commands
CMD_AWK="/bin/awk"
CMD_EGREP="/bin/egrep"
# Temporary work file (will be removed automatically)
TEMP_FILE="/tmp/check_oracle_tablespace_$$.tmp"
BLADE_PATCH="/usr/local/nagios/blade/cardblade.txt"
# Nagios plugin return values
RET_OK=0
RET_WARNING=1
RET_CRITICAL=2
RET_UNKNOWN=3
# Default values
THRESHOLD_ERROR=0
WARNING_THRESHOLD=-1
WARNING_EXCEEDED=0
WARNING_STATUS_TEXT=""
CRITICAL_THRESHOLD=-1
CRITICAL_EXCEEDED=0
CRITICAL_STATUS_TEXT=""
OK_STATUS_TEXT=""
CHECK_AUTOEXTENSION=0
VERBOSE=0
# ------------------------------ FUNCTIONS -------------------------------------
printInfo() {
echo "Nagios 检测egenera刀片硬件状态插件"
echo "Copyright (C) 2007 ."
}
printHelp() {
echo
echo "Usage: blade.sh -p <Pblade号> -w <Temp> -c <Temp> "
echo
echo " -p pblade号"
echo " -w CPU温度警告值 (整数)"
echo " -c CPU温度危险值(整数)"
echo " -h this help screen"
echo " -l license info"
echo " -V version info"
echo
echo "举例: blade.sh -p 2 -w 60 -c 70"
echo
}
printLicense() {
echo
echo "This program is free software; you can redistribute it and/or"
echo "modify it under the terms of the GNU General Public License"
echo "as published by the Free Software Foundation; either version 2"
echo "of the License, or (at your option) any later version."
echo
echo "This program is distributed in the hope that it will be useful,"
echo "but WITHOUT ANY WARRANTY; without even the implied warranty of"
echo "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the"
echo "GNU General Public License for more details."
echo
echo "You should have received a copy of the GNU General Public License"
echo "along with this program; if not, write to the Free Software"
echo "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA."
echo
}
printVersion() {
echo
echo "\$Id: blade.sh,v 1.7 2007/02/16 09:41:16 kivimaki Exp $"
echo
}
# Checks command line options (pass $@ as parameter).
checkOptions() {
if [ $# -eq 0 ]; then
printInfo
printHelp
exit $RET_UNKNOWN
fi
while getopts p:w OPT $@; do
case $OPT in
p) # Pblade ID
PBLADE_ID="$OPTARG"
;;
w) #Temp warning
WARNING_THRESHOLD=$OPTARG
;;
c) # Temp critical
CRITICAL_THRESHOLD=$OPTARG
;;
l) printInfo
printLicense
exit $RET_OK
;;
h) printInfo
printHelp
exit $RET_OK
;;
v) VERBOSE=1
;;
V) printInfo
printVersion
exit $RET_OK
;;
?) printInfo
printHelp
exit $RET_UNKNOWN
;;
esac
done
TMP=$(grep "^MyBladeFrame/${PBLADE_ID} " $BLADE_PATCH)
if [ -z "$PBLADE_ID" ] || [ "$TMP" = "" ]; then
echo "Error: Invalid PBLADE_ID (see $BLADE_PATCH)."
printInfo
printHelp
exit $RET_OK
else
PBLADE_STAT=$(echo $TMP|awk '{print $3}')
fi
#echo $TMP
#MyBladeFrame/p3 B Booted test/rac03 2 2.67GHz 16GB IA-32E 475
bl=$(echo $TMP|awk '{print $1}')
stat=$(echo $TMP|awk '{print $3}')
pserver=$(echo $TMP|awk '{print $4}')
cpu_num=$(echo $TMP|awk '{print $5}')
cpu=$(echo $TMP|awk '{print $6}')
mem=$(echo $TMP|awk '{print $7}')
power=$(echo $TMP|awk '{print $9}')
echo 第"$PBLADE_ID"块刀片:、状态:"$stat"、pserver系统:"$pserver"、cpu数"$cpu_num"、cpu主频:"$cpu"、内存:"$mem"、电源功率:"$power"W
if [ "$PBLADE_STAT" != "Booted" ] && [ "$PBLADE_STAT" != "On" ]; then
exit $RET_CRITICAL
else
exit $RET_OK
fi
}
# ----------------------------- MAIN PROGRAM -----------------------------------
checkOptions $@