自定义脚本监控端口和进程,脚本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