bash script, command substitution & assigning a variable

Live forum: /viewtopic.php?t=80

chad

08-12-2004 08:34:18

I having difficulty creating a little script that gets the page count OID from some HP printers. Here's the script:


#!/bin/bash

logdir=/var/log/page_counts
date=`date +%Y%m%d\ %T`
printers_list="hp4-2c hp4-3c hp4-4c"

for printer in $printers_list
do
count=$(snmpget -O qv -c public -v 1 $printer 1.1.3.6.1.2.1.43.10.2.1.4.1.1)
#echo $date $count >> $logdir/$printer
echo $date $count
done


It seems the $printer var is not being referenced correctly in the command substitution part of count$=(snmpget.... ). Can somebody help out a rookie shell scripter?

Oh, here's a copy of the error I get when running the script:


Error in packet
Reason: (noSuchName) There is no such variable name in this MIB.
Failed object: iso.1.3.6.1.2.1.43.10.2.1.4.1.1

chad

08-12-2004 09:48:44

Nevermind... :oops:

It helps a TON if you get the OID correct. Instead of 1.1.3.6.1.2.1.43.10.2.1.4.1.1 it should be 1.3.6.1.2.1.43.10.2.1.4.1.1.

All is well.

chad

08-12-2004 10:00:42

FYI, here's the final script:

#!/bin/bash

logdir=/var/log/page_counts
now=`date +%Y%m%d\ %T`
printers_list="hp4-2c hp4-3c hp4-4c hp4-pfc1 hp4-cml6 hp4-fo1 hp4-fo3 hp4-fo4 hp4-hr1 hp4k-a1 hp4-ps1 hp4-uw1 hp5-3adm hp5-cml1 hp5-cs2 hp5si-a1 hp4-opr1 hp4-pa3 hp4-2adm hp2500cm-1 hp8k-is1 hp8k-is2 hp5si-g1"

for printer in $printers_list
do
count=$(snmpget -O qv -c public -v 1 $printer 1.3.6.1.2.1.43.10.2.1.4.1.1)
echo $now $count >> $logdir/$printer
done