Favor of the day? Can't get division to work in my script

compslckr

[H]F Junkie
Joined
Jun 5, 2002
Messages
8,930
Basically I am writing a script to grab values through SNMP then display them in an easy to read format.

I have a printers file that contains a list of IP addresses for my printers.

The script I have is basically a clone from Cisco CookBook (using snmp to gather info about cisco devices).

The only thing I am having problems with is the division in the output; basically I want to divice $currentpages by $maxpages to get a percentage of toner cartridge remaining.

Code:
#!/bin/sh
#Get info about HP Printers
#
workingdir="/home/scripts/snmp"
snmp="snmpget -v 1 -c public"
#
LOG=$workingdir/RESULT.txt
infile=$workingdir/printer-list
`rm $workingdir/RESULT.txt`
#
while read device
do
    $snmp $device sysName.0 > /dev/null
    if [ "$?" = "0" ] ; then
    toner=`snmpget -v1 -c public $device mib-2.43.11.1.1.6.1.1 | awk '{print $4" "$5" "$6" "$7" "$8}'`
    maintkit=`snmpget -v1 -c public $device mib-2.43.11.1.1.6.1.2 | awk '{print $4" "$5" " $6" " $7" "$8}'`
    currentpages=`snmpget -v2c -c public $device mib-2.43.11.1.1.9.1.1 | awk '{print $4}'`
    maxpages=`snmpget -v2c -c public $device mib-2.43.11.1.1.8.1.1 | awk '{print $4}'`    
    echo -e "Printer: $device\nToner Type: $toner\nMaintenance Kit: $maintkit\n$currentpages\n$maxpages\n$(($currentpages / $maxpages))\n\n" << $LOG
fi
done < $infile
My output looks like this

Code:
Printer: prt-1
Toner Type: "Black Cartridge HP C8543X" 
Maintenance Kit: "Maintenance Kit HP 110V-C9152A, 220V-C9153A"
4180
38000
0


Printer: prt-2
Toner Type: "Black Cartridge HP C8543X" 
Maintenance Kit: "Maintenance Kit HP 110V-C9152A, 220V-C9153A"
18620
38000
0


Printer: prt-3
Toner Type: "Black Print Cartridge HP C8543X"
Maintenance Kit: "Maintenance Kit HP 110V-C9152A, 220V-C9153A"
7200
30000
0
adding numbers seems to work, just not with the variables
Code:
echo $((10 / 2))
5
 
Last edited:
Got it figured out and I feel retarded. the below string is working

Code:
    echo -e "Printer: $device\nToner Type: $toner\nMaintenance Kit: $maintkit\n$currentpages\n$maxpages\n $((100 * $currentpages /$maxpages))%"
 
Back
Top