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

image

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

  • 自定义脚本监控端口和进程,脚本
[root@mysql02 data]# cat process_port_check.sh

#!/bin/bash
############################################
#$name: process_port_check.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
posted @ 2019-04-28 17:18  SRE运维充电站  阅读(1665)  评论(0编辑  收藏  举报