脚本内容:
#!/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"