ZABBIX开发自定义进程关键字监控

脚本内容:

#!/bin/sh

###################################################
# Used to monitor the number of process keywords
# script by shell
# writed by Deliver
# 2022/11/15
###################################################
# 脚本运行超时处理
source /home/zabbix/zabbix-agent/etc/scripts/zabbixtimeout.sh
##########################################################################

ProcName=$1
ProcUser=$2
if [ -n "$ProcUser" ];then
if [ -n "$ProcName" ];then
#ProcNum=`ps -fu $ProcUser|grep "$ProcName"|grep -v grep |grep -v $0|wc -l`
ProcNum=`ps -ef|grep "$ProcName"|grep -v grep |awk '{if ($1=="'$ProcUser'") print $0}' |grep -v $0|wc -l`
else
#ProcNum=`ps -fu $ProcUser|grep -v grep |grep -v $0|wc -l`
ProcNum=`ps -ef|grep -v grep |awk '{if ($1=="'$ProcUser'") print $0}' |grep -v $0|wc -l`
fi
else
if [ -n "$ProcName" ];then
ProcNum=`ps -ef|grep "$ProcName"|grep -v grep |grep -v $0|wc -l`
else
ProcNum=`ps -ef|grep -v grep |grep -v $0|wc -l`
fi
fi
echo "$ProcNum"

posted @ 2022-11-19 00:24  呼长喜  阅读(48)  评论(0编辑  收藏  举报