代码:
来源:http://blog.chinaunix.net/u2/84280/showart_2311724.html
#!/bin/bash
#author Sky
PATH="/var/PROGRAM/MANAGEMENT/modules/xbash:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:"
LANG=zh_CN
export PATH LANG
RESINHOME="/data/resin-pro-3.1.8"
PLUGIN_HOME=$RESINHOME/pconline_plugin
JAVAHOME="/usr/java/jdk1.6.0_06"
PLUGIN_MC="java_memcached-release_2.0.1.jar"
PLUGIN_LOG4J="log4j-1.2.15.jar"
PLUGIN_NAME="mcheathychk.jar"
#############enviroment initialize###################
[[ ! -e $JAVAHOME/jre/lib/ext/$PLUGIN_MC ]] && cp $RESINHOME/pconline_plugin/$PLUGIN_MC $JAVAHOME/jre/lib/ext/
[[ ! -e $JAVAHOME/jre/lib/ext/$PLUGIN_LOG4J ]] && cp $RESINHOME/pconline_plugin/$PLUGIN_LOG4J $JAVAHOME/jre/lib/ext/
####################################################
############
# 主机信息 #
############
INTF=$(netstat -rn | tail -1 | awk '{print $NF}')
IP=$(ifconfig $INTF | awk '/inet addr/{ split($2,tmp,":") ; print tmp[2] }')
HOST_NAME=$(hostname --short)
##########
#邮件环境#
##########
#CHARTSET="zh_CN."
MAIL_CLIENT=""
MAIL_SENDER=""
MAIL_SERVER=""
case $IP in
192.168.230.*|192.168.1[0-1].*|192.168.238.*|202.9.1.*)
MAIL_SERVER="202.2"
;;
*)
MAIL_SERVER="192.168.8."
;;
esac
##########
for resin in `cat /etc/mods.conf | grep resind | grep -v "#" | awk -F":" '{print $2}' | xargs`
do
######get relate configuration#####################
JAVAHOME=`cat $resin | grep "JAVA_HOME=" | awk -F"=" '{print $2}'`
RESINHOME=`cat $resin | grep "RESIN_HOME=" | awk -F"=" '{print $2}'`
CONF_NAME=`cat $resin | grep "SEARCH_STR=" | awk -F"=" '{print $2}' | sed 's/\"//g'`
APP_HOME=`cat $RESINHOME/conf/$CONF_NAME | grep "<web-app id=\"/\" root-directory=\"" | awk -F"=" '{print $3}' | sed "s#\"##g" | sed "s#/>##g"`
CONF_MC=$APP_HOME/WEB-INF/classes/memcached.properties
###################################################
if [[ -e $CONF_MC ]] ; then
servers=`cat $CONF_MC | grep "servers" | awk -F"=" '{print $2}'`
for server in `echo $servers | awk -F"," '{for( i=0;i<$NF;i++) {print $((i+1))}}' | xargs`
do
#echo $server
echo $server | awk -F":" '{print $1,$2}' | \
while read dip port
do
if /sbin/iptables -nL | grep -q "$dip"
then
######解封###############
/sbin/iptables -D OUTPUT -p tcp -s $IP -d $dip --dport $port -j REJECT --reject-with tcp-reset 2> /dev/null
fi
done
##############Test Memcache################
stats=`$JAVAHOME/bin/java -jar $RESINHOME/pconline_plugin/$PLUGIN_NAME $server 2> /dev/dull`
#echo "stats="$stats
if [[ $stats == "MCOK" ]] ; then
agentname=`echo $resin | awk -F"_" '{print $2}'`
echo "mcchk_$agentname=0"
else
agentname=`echo $resin | awk -F"_" '{print $2}'`
echo $server | awk -F":" '{print $1,$2}' | \
while read dip port
do
/sbin/iptables -A OUTPUT -p tcp -s $IP -d $dip --dport $port -j REJECT --reject-with tcp-reset
done
echo "mcchk_$agentname=1"
echo $agentname"_"$server" is bad" | env MAILRC=/dev/null charset="$CHARTSET" from="$MAIL_SENDER" smtp="$MAIL_SERVER" \
nail -n -s "$HOST_NAME($IP)MC had bad information" $MAIL_CLIENT
fi
done
else
agentname=`echo $resin | awk -F"_" '{print $2}'`
echo "mcchk_$agentname=0"
break
fi
done
#author Sky
PATH="/var/PROGRAM/MANAGEMENT/modules/xbash:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:"
LANG=zh_CN
export PATH LANG
RESINHOME="/data/resin-pro-3.1.8"
PLUGIN_HOME=$RESINHOME/pconline_plugin
JAVAHOME="/usr/java/jdk1.6.0_06"
PLUGIN_MC="java_memcached-release_2.0.1.jar"
PLUGIN_LOG4J="log4j-1.2.15.jar"
PLUGIN_NAME="mcheathychk.jar"
#############enviroment initialize###################
[[ ! -e $JAVAHOME/jre/lib/ext/$PLUGIN_MC ]] && cp $RESINHOME/pconline_plugin/$PLUGIN_MC $JAVAHOME/jre/lib/ext/
[[ ! -e $JAVAHOME/jre/lib/ext/$PLUGIN_LOG4J ]] && cp $RESINHOME/pconline_plugin/$PLUGIN_LOG4J $JAVAHOME/jre/lib/ext/
####################################################
############
# 主机信息 #
############
INTF=$(netstat -rn | tail -1 | awk '{print $NF}')
IP=$(ifconfig $INTF | awk '/inet addr/{ split($2,tmp,":") ; print tmp[2] }')
HOST_NAME=$(hostname --short)
##########
#邮件环境#
##########
#CHARTSET="zh_CN."
MAIL_CLIENT=""
MAIL_SENDER=""
MAIL_SERVER=""
case $IP in
192.168.230.*|192.168.1[0-1].*|192.168.238.*|202.9.1.*)
MAIL_SERVER="202.2"
;;
*)
MAIL_SERVER="192.168.8."
;;
esac
##########
for resin in `cat /etc/mods.conf | grep resind | grep -v "#" | awk -F":" '{print $2}' | xargs`
do
######get relate configuration#####################
JAVAHOME=`cat $resin | grep "JAVA_HOME=" | awk -F"=" '{print $2}'`
RESINHOME=`cat $resin | grep "RESIN_HOME=" | awk -F"=" '{print $2}'`
CONF_NAME=`cat $resin | grep "SEARCH_STR=" | awk -F"=" '{print $2}' | sed 's/\"//g'`
APP_HOME=`cat $RESINHOME/conf/$CONF_NAME | grep "<web-app id=\"/\" root-directory=\"" | awk -F"=" '{print $3}' | sed "s#\"##g" | sed "s#/>##g"`
CONF_MC=$APP_HOME/WEB-INF/classes/memcached.properties
###################################################
if [[ -e $CONF_MC ]] ; then
servers=`cat $CONF_MC | grep "servers" | awk -F"=" '{print $2}'`
for server in `echo $servers | awk -F"," '{for( i=0;i<$NF;i++) {print $((i+1))}}' | xargs`
do
#echo $server
echo $server | awk -F":" '{print $1,$2}' | \
while read dip port
do
if /sbin/iptables -nL | grep -q "$dip"
then
######解封###############
/sbin/iptables -D OUTPUT -p tcp -s $IP -d $dip --dport $port -j REJECT --reject-with tcp-reset 2> /dev/null
fi
done
##############Test Memcache################
stats=`$JAVAHOME/bin/java -jar $RESINHOME/pconline_plugin/$PLUGIN_NAME $server 2> /dev/dull`
#echo "stats="$stats
if [[ $stats == "MCOK" ]] ; then
agentname=`echo $resin | awk -F"_" '{print $2}'`
echo "mcchk_$agentname=0"
else
agentname=`echo $resin | awk -F"_" '{print $2}'`
echo $server | awk -F":" '{print $1,$2}' | \
while read dip port
do
/sbin/iptables -A OUTPUT -p tcp -s $IP -d $dip --dport $port -j REJECT --reject-with tcp-reset
done
echo "mcchk_$agentname=1"
echo $agentname"_"$server" is bad" | env MAILRC=/dev/null charset="$CHARTSET" from="$MAIL_SENDER" smtp="$MAIL_SERVER" \
nail -n -s "$HOST_NAME($IP)MC had bad information" $MAIL_CLIENT
fi
done
else
agentname=`echo $resin | awk -F"_" '{print $2}'`
echo "mcchk_$agentname=0"
break
fi
done
来源:http://blog.chinaunix.net/u2/84280/showart_2311724.html
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:http://jackxiang.com/post/3796/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
评论列表