Python SNMP simple example to get 1 OID

Because it took me forever to piece this simple code together

import netsnmp
session = netsnmp.Session( DestHost='your.host.com', Version=2, Community='public' )
vars = netsnmp.VarList( netsnmp.Varbind('.1.3.6.1.4.1.2021.8.1.101.1') )
print( session.get(vars) )

Shell scripting – updating a file holding a counter

counter=`cat /tmp/counter` ; echo "$counter+1" | bc > /tmp/counter

note that loading the /tmp/counter into the variable is a necessary indirection, the following:

echo "`cat /tmp/counter`+1" | bc > /tmp/counter

would not work as the output redirection gets triggered before the cat gets a chance to happen, so the file is emptied too early.