Created
December 28, 2018 20:36
-
-
Save harish2704/03d013507b3106d6681552c6e014687d to your computer and use it in GitHub Desktop.
Count number of process matching given process name and arguments using snmp protocol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
listProcessNameMib=.1.3.6.1.2.1.25.4.2.1.2 | |
listProcessArgsMib=.1.3.6.1.2.1.25.4.2.1.5 | |
snmpHost=$1 | |
snmpCommunity=$2 | |
shift | |
shift | |
processName=$@ | |
if [ -z "$processName" ]; then | |
cat<<EOF | |
Usage: snmp_check_process.sh <snmp_host_ip> <snmp_community> <process_name> [ process_args] * | |
Returns number of process matches given process name ( including arguments ). | |
Eg: | |
# snmp_check_process.sh localhost public python /home/user1/*.py | |
EOF | |
exit -1 | |
fi | |
join -j1 <(snmpwalk -O n -v 1 -c $snmpCommunity $snmpHost $listProcessNameMib | sed "s/^$listProcessNameMib.\([0-9]*\) = .*\"\(.*\)\"\$/\1 \2/") <( snmpwalk -O n -v 1 -c $snmpCommunity $snmpHost $listProcessArgsMib | sed "s/^$listProcessArgsMib.\([0-9]*\) = .*\"\(.*\)\"\$/\1 \2/" ) | grep "$processName" | wc -l |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment