标签:shell
一、 #!/bin/sh #Caiyuan NAGIOS SCRIPT export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin PORT=$1 PORT_nginx=‘80‘ PORT_php=‘9000‘ PORT_mysql=‘3306‘ PORT_pgsql=‘5432‘ PORT_memcached1=‘11211‘ PORT_memcached2=‘11212‘ PORT_mongod_conf1=‘28001‘ PORT_mongod_conf2=‘28002‘ PORT_mongod_conf3=‘28003‘ PORT_mongod_rs1_1=‘27017‘ PORT_mongod_rs1_2=‘27018‘ PORT_mongod_rs1_a=‘27019‘ PORT_mongos=‘30000‘ function cy_nginx() { netstat -antpl|grep -w $PORT_nginx > /dev/null if [ "$?" != "0" ];then echo "Nginx:$PORT_nginx is down." exit 2 else echo "Nginx:$PORT_nginx is running." exit 0 fi } function cy_php() { netstat -antpl|grep -w $PORT_php > /dev/null if [ "$?" != "0" ];then echo "php:$PORT_php is down." exit 2 else echo "php:$PORT_php is running." exit 0 fi } function cy_mysql() { netstat -antpl|grep -w $PORT_mysql > /dev/null if [ "$?" != "0" ];then echo "mysql:$PORT_mysql is down." exit 2 else echo "mysql:$PORT_mysql is running." exit 0 fi } function pgsql() { netstat -antpl|grep -w $PORT_pgsql > /dev/null if [ "$?" != "0" ];then echo "pgsql:$PORT_pgsql is down." exit 2 else echo "pgsql:$PORT_pgsql is running." exit 0 fi } function memcached1() { netstat -antpl|grep -w $PORT_memcached1 > /dev/null if [ "$?" != "0" ];then echo "memcached:$PORT_memcached1 is down." exit 2 else echo "memcached:$PORT_memcached1 is running." exit 0 fi } function memcached2() { netstat -antpl|grep -w $PORT_memcached2 > /dev/null if [ "$?" != "0" ];then echo "memcahched:$PORT_memcached2 is down." exit 2 else echo "memcahched:$PORT_memcached2 is running." exit 0 fi } function mongod_conf1() { netstat -antpl|grep -w $PORT_mongod_conf1 > /dev/null if [ "$?" != "0" ];then echo "mongod_conf1:$PORT_mongod_conf1 is down." exit 2 else echo "mongod_conf1:$PORT_mongod_conf1 is running." exit 0 fi } function mongod_conf2() { netstat -antpl|grep -w $PORT_mongod_conf2 > /dev/null if [ "$?" != "0" ];then echo "mongod_conf2:$PORT_mongod_conf2 is down." exit 2 else echo "mongod_conf2:$PORT_mongod_conf2 is running." exit 0 fi } function mongod_conf3() { netstat -antpl|grep -w $PORT_mongod_conf3 > /dev/null if [ "$?" != "0" ];then echo "mongod_conf3:$PORT_mongod_conf3 is down." exit 2 else echo "mongod_conf3:$PORT_mongod_conf3 is running." exit 0 fi } function mongod_rs1_1() { netstat -antpl|grep -w $PORT_mongod_rs1_1 > /dev/null if [ "$?" != "0" ];then echo "mongod_rs1_1:$PORT_mongod_rs1_1 is down." exit 2 else echo "mongod_rs1_1:$PORT_mongod_rs1_1 is running." exit 0 fi }} function cy_php() { netstat -antpl|grep -w $PORT_php > /dev/null if [ "$?" != "0" ];then echo "php:$PORT_php is down." exit 2 else echo "php:$PORT_php is running." exit 0 fi } function cy_mysql() { netstat -antpl|grep -w $PORT_mysql > /dev/null if [ "$?" != "0" ];then echo "mysql:$PORT_mysql is down." exit 2 else echo "mysql:$PORT_mysql is running." exit 0 fi } function pgsql() { netstat -antpl|grep -w $PORT_pgsql > /dev/null if [ "$?" != "0" ];then echo "pgsql:$PORT_pgsql is down." exit 2 else echo "pgsql:$PORT_pgsql is running." exit 0 fi } function memcached1() { netstat -antpl|grep -w $PORT_memcached1 > /dev/null if [ "$?" != "0" ];then echo "memcached:$PORT_memcached1 is down." exit 2 else echo "memcached:$PORT_memcached1 is running." exit 0 fi } function memcached2() { netstat -antpl|grep -w $PORT_memcached2 > /dev/null if [ "$?" != "0" ];then echo "memcahched:$PORT_memcached2 is down." exit 2 else echo "memcahched:$PORT_memcached2 is running." exit 0 fi } function mongod_conf1() { netstat -antpl|grep -w $PORT_mongod_conf1 > /dev/null if [ "$?" != "0" ];then echo "mongod_conf1:$PORT_mongod_conf1 is down." exit 2 else echo "mongod_conf1:$PORT_mongod_conf1 is running." exit 0 fi } function mongod_conf2() { netstat -antpl|grep -w $PORT_mongod_conf2 > /dev/null if [ "$?" != "0" ];then echo "mongod_conf2:$PORT_mongod_conf2 is down." exit 2 else echo "mongod_conf2:$PORT_mongod_conf2 is running." exit 0 fi } function mongod_conf3() { netstat -antpl|grep -w $PORT_mongod_conf3 > /dev/null if [ "$?" != "0" ];then echo "mongod_conf3:$PORT_mongod_conf3 is down." exit 2 else echo "mongod_conf3:$PORT_mongod_conf3 is running." exit 0 fi } function mongod_rs1_1() { netstat -antpl|grep -w $PORT_mongod_rs1_1 > /dev/null if [ "$?" != "0" ];then echo "mongod_rs1_1:$PORT_mongod_rs1_1 is down." exit 2 else echo "mongod_rs1_1:$PORT_mongod_rs1_1 is running." exit 0 fi } function mongod_rs1_2() { netstat -antpl|grep -w $PORT_mongod_rs1_2 > /dev/null if [ "$?" != "0" ];then echo "mongod_rs1_2:$PORT_mongod_rs1_2 is down." exit 2 else echo "mongod_rs1_2:$PORT_mongod_rs1_2 is running." exit 0 fi } function mongod_rs1_a() { netstat -antpl|grep -w $PORT_mongod_rs1_a > /dev/null if [ "$?" != "0" ];then echo "mongod_rs1_a:$PORT_mongod_rs1_a is down." exit 2 else echo "mongod_rs1_a:$PORT_mongod_rs1_a is running." exit 0 fi } function cy_mongos() { netstat -antpl|grep -w $PORT_mongos > /dev/null if [ "$?" != "0" ];then echo "mongos:$PORT_mongos is down." exit 2 else echo "mongos:$PORT_mongos is running." exit 0 fi } cy_keepalived() { gpid=`ps -ef|grep "keepalived"|grep -v grep|wc -l` if [ "$gpid" -gt "2" ];then echo "Keepalived is running." exit 0 elif [ "$gpid" -eq "2" ];then echo "Keepalived is down.Please check." exit 2 else echo "取值异常" exit 1 fi } $PORT-w $PORT_mongos > /dev/null if [ "$?" != "0" ];then echo "mongos:$PORT_mongos is down." exit 2 else echo "mongos:$PORT_mongos is running." exit 0 fi } cy_keepalived() { gpid=`ps -ef|grep "keepalived"|grep -v grep|wc -l` if [ "$gpid" -gt "2" ];then echo "Keepalived is running." exit 0 elif [ "$gpid" -eq "2" ];then echo "Keepalived is down.Please check." exit 2 else echo "取值异常" exit 1 fi } $PORT 二、#!/bin/sh #MYCALL APP NAGIOS SCRIPT export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin APP=$1 TOM_PORT=‘8080‘ NGI_PORT=‘80‘ MOS_PORT=‘3000‘ # MOD_PORT1=‘27017‘ MOD_PORT2=‘27018‘ MOD_PORT3=‘27019‘ MOC_PORT1=‘28001‘ MOC_PORT2=‘28002‘ MOC_PORT3=‘28003‘ # FDT_PORT=‘22122‘ FDS_PORT=‘23000‘ RED_PORT=‘6379‘ MSP_PORT=‘63880‘ FS_PORT=‘8001‘ OPR_PORT=‘5222‘ function MONGODB1() { netstat -antl|grep $MOD_PORT1 > /dev/null if [ "$?" != "0" ];then echo "Mongodb:$MOD_PORT1 is down." exit 2 else echo "Mongodb:$MOD_PORT1 is running." exit 0 fi } function MONGODB2() { netstat -antl|grep $MOD_PORT2 > /dev/null if [ "$?" != "0" ];then echo "Mongodb:$MOD_PORT2 is down." exit 2 else echo "Mongodb:$MOD_PORT2 is running." exit 0 fi } function MONGODB3() { netstat -antl|grep $MOD_PORT3 > /dev/null if [ "$?" != "0" ];then echo "Mongodb:$MOD_PORT3 is down." exit 2 else echo "Mongodb:$MOD_PORT3 is running." exit 0 fi } function MONGO_CONFIG1() { netstat -antl|grep $MOC_PORT1 > /dev/null if [ "$?" != "0" ];then echo "Mongodb Config:$MOC_PORT1 is down." exit 2 else echo "Mongodb Config:$MOC_PORT1 is running." exit 0 fi } function MONGO_CONFIG2() { netstat -antl|grep $MOC_PORT2 > /dev/null if [ "$?" != "0" ];then echo "Mongodb Config:$MOC_PORT2 is down." exit 2 else echo "Mongodb Config:$MOC_PORT2 is running." exit 0 fi } function MONGO_CONFIG3() { netstat -antl|grep $MOC_PORT3 > /dev/null if [ "$?" != "0" ];then echo "Mongodb Config:$MOC_PORT3 is down." exit 2 else echo "Mongodb Config:$MOC_PORT3 is running." exit 0 fi } function OPENFIRE() { netstat -antl|grep $OPR_PORT > /dev/null if [ "$?" != "0" ];then echo "Openfire:$OPR_PORT is down." exit 2 else echo "Openfire:$OPR_PORT is running." exit 0 fi } function MSGPUSH() { netstat -ntl|grep $MSP_PORT > /dev/null if [ "$?" != "0" ];then echo "MSGPUSH:$MSP_PORT is down." exit 2 else echo "MSGPUSH:$MSP_PORT is running." exit 0 fi } function NGINX() { ps aux|grep nginx|grep -v grep > /dev/null if [ "$?" != "0" ];then echo "Nginx is down." exit 2 else echo "Nginx is running." exit 0 fi } function FS() { netstat -ntl|grep $FS_PORT > /dev/null if [ "$?" != "0" ];then echo "Fastdfs Socket (fs_socket.jar):$FS_PORT is down." exit 2 else echo "Fastdfs Socket (fs_socket.jar):$FS_PORT is running." exit 0 fi } function FAST_T() { netstat -ntl|grep $FDT_PORT > /dev/null if [ "$?" != "0" ];then echo "Fastdfs Tracker:$FDT_PORT is down." exit 2 else echo "Fastdfs Tracker:$FDT_PORT is running." exit 0 fi } function FAST_S() { netstat -ntl|grep $FDS_PORT > /dev/null if [ "$?" != "0" ];then echo "Fastdfs Storage:$FDS_PORT is down." exit 2 else echo "Fastdfs Storage:$FDS_PORT is running." exit 0 fi } function MQ() { ps aux|grep java|grep mq > /dev/null if [ "$?" != "0" ];then echo "Active MQ is down." exit 2 else echo "Active MQ is running." exit 0 fi } function ZOOKEEPER() { ps aux|grep java|grep zookeep > /dev/null if [ "$?" != "0" ];then echo "Zookeeper is down." exit 2 else echo "Zookeeper is running." exit 0 fi } function TOMCAT() { netstat -ntl|grep "$TOM_PORT" > /dev/null if [ "$?" != "0" ];then echo "Tomcat:$TOM_PORT is down." exit 2 else echo "Tomcat:$TOM_PORT is running." exit 0 fi } function BACKSERVICE() { ps aux|grep java|grep ‘back_service‘ > /dev/null if [ "$?" != "0" ];then echo "Backservice is down." exit 2 else echo "Backservice is running." exit 0 fi } function REDIS() { netstat -ntl|grep $RED_PORT > /dev/null if [ "$?" != "0" ];then echo "Redis:$RED_PORT is down." exit 2 else echo "Redis:$RED_PORT is running." exit 0 fi } $APP 以上脚本还是挺实用的吧,,个人觉得,,大家可以根据自己企业环境做相应变化
本文出自 “毛毛鸭” 博客,请务必保留此出处http://woshitieren.blog.51cto.com/2466034/1683827
标签:shell
原文地址:http://woshitieren.blog.51cto.com/2466034/1683827