zabbix監控進程和端口存活腳本

自定義腳本監控端口和進程,腳本process_port_check.sh 內容:mysql


[root@mysql02 data]# cat test.sh nginx

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


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
}bash

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進程

腳本測試test

data]# bash test.sh port 80 #端口測試
0
data]# bash test.sh process httpd #服務運行測試
0監控

相關文章
相關標籤/搜索