simple math , what am I missing ?

ml1782r

New Member
Joined
Jan 29, 2022
Messages
5
Reaction score
1
Credits
52
asimple math subtraction and its giving me a fit.

I'm doing an snmp walk getting a value and then waiting a period of time and doing it again. Then subtracting to get the difference. I know the diff isn't 0

[#!/bin/bash
#
OLD= snmpwalk -v2c -c AE4ML 192.168.20.254 | grep 'iso.3.6.1.2.1.31.1.1.1.6.2 =' | awk -F ' ' '{print $4}'
#
#
sleep 10
#
NEW= snmpwalk -v2c -c AE4ML 192.168.20.254 | grep 'iso.3.6.1.2.1.31.1.1.1.6.2 =' | awk -F ' ' '{print $4}'
(( TOTAL=NEW-OLD))
echo "$((NEW - OLD))"]

RESULTS:
./process.sh
133136725551
133147152935
0
 


Maybe try this, without the square brackets.

#!/bin/bash

# Store the old value
OLD=$(snmpwalk -v2c -c AE4ML 192.168.20.254 | grep 'iso.3.6.1.2.1.31.1.1.1.6.2 =' | awk -F ' ' '{print $4}')

# Sleep for 10 seconds
sleep 10

# Store the new value
NEW=$(snmpwalk -v2c -c AE4ML 192.168.20.254 | grep 'iso.3.6.1.2.1.31.1.1.1.6.2 =' | awk -F ' ' '{print $4}')

# Calculate the difference
TOTAL=$((NEW - OLD))

echo "Difference: $TOTAL"
 
Last edited:
Maybe try this, without the square brackets.

#!/bin/bash

# Store the old value
OLD=$(snmpwalk -v2c -c AE4ML 192.168.20.254 | grep 'iso.3.6.1.2.1.31.1.1.1.6.2 =' | awk -F ' ' '{print $4}')

# Sleep for 10 seconds
sleep 10

# Store the new value
NEW=$(snmpwalk -v2c -c AE4ML 192.168.20.254 | grep 'iso.3.6.1.2.1.31.1.1.1.6.2 =' | awk -F ' ' '{print $4}')

# Calculate the difference
TOTAL=$((NEW - OLD))

echo "Difference: $TOTAL"


======
Same results as I got before. Seems to me I tried that variation earlier.

Thank you

./process.sh
133346325654
133346364694
value is : 0
 
Maybe try this, without the square brackets.

#!/bin/bash

# Store the old value
OLD=$(snmpwalk -v2c -c AE4ML 192.168.20.254 | grep 'iso.3.6.1.2.1.31.1.1.1.6.2 =' | awk -F ' ' '{print $4}')

# Sleep for 10 seconds
sleep 10

# Store the new value
NEW=$(snmpwalk -v2c -c AE4ML 192.168.20.254 | grep 'iso.3.6.1.2.1.31.1.1.1.6.2 =' | awk -F ' ' '{print $4}')

# Calculate the difference
TOTAL=$((NEW - OLD))

echo "Difference: $TOTAL"

=======
Thank you,
That was the answer. The one variation that I never thought of .
 
Your initial try would have set an environment varialbe called "OLD" to nothing and with that, execute the stuff after the space (without setting the variable with the result). The 2 values are the direct output of snmpwalk -v2c -c AE4ML 192.168.20.254 | grep 'iso.3.6.1.2.1.31.1.1.1.6.2 =' | awk -F ' ' '{print $4}'
 

Members online


Top