#!/bin/sh
#
# found if this IP is receiving data
#
#echo hexIpAdd=`sh convertIPAddressToHex $1`
hexIpAdd='C0 A8 01 02'
#`snmpwalk -v 2c -c public 192.168.252.187 .1.3.6.1.4.1.231.7.1.2.2.1.4.7.13.1.1.3301 | grep '$hexIpAdd' | wc -l`
if [ `snmpwalk -v 2c -c public 192.168.252.187 .1.3.6.1.4.1.231.7.1.2.2.1.4.7.13.1.1.3301 | grep '$hexIpAdd' | wc -l` -gt 0 ]; then
echo "Value FOUND!!"
else
echo "Value NOT FOUND!!"
fi
The code is very simple, I convert my an regular IP to a hexadecimal one, and query via SNMPWALK a network equipment to see if the converted IP is receiving streaming.
The problem is, that the grep pipe is failing to use the VARIABLE, with means if I replace the "grep '$hexIpAdd'" with this "grep 'C0 A8 01 02'" it works.
if snmpwalk -v 2c -c public 192.168.252.187 .1.3.6.1.4.1.231.7.1.2.2.1.4.7.13.1.1.3301 | grep -q "$hexIpAdd"; then