Skip to content

Instantly share code, notes, and snippets.

@harish2704
Created December 28, 2018 20:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harish2704/03d013507b3106d6681552c6e014687d to your computer and use it in GitHub Desktop.
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
#!/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