zabbix监控进程和端口存活脚本


自定义脚本监控端口和进程,脚本process_port_check.sh 内容:


[root@mysql02 data]# cat test.sh

#!/bin/bash
############################################
#$name: nginx_status.sh
#author: daizhe
#Create Date: 2019-02-13
############################################


check_process(){
NUM=`ps -ef | grep -v grep | grep -v bash | grep ${NAME} | wc -l`
if [ $NUM -eq 0 ];then
echo 1
else
echo 0
fi
}

check_port(){
ss -tnl | grep ${PORT} &> /dev/null
if [ $? -eq 0 ];then
echo 0
else
echo 1
fi
}

main(){
case $1 in
process)
NAME=$2
check_process;
;;
port)
PORT=$2
check_port;
;;
esac
}
main $1 $2

脚本测试

data]# bash test.sh port 80 #端口测试
0
data]# bash test.sh process httpd #服务运行测试
0


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM