On 10/3/07, Darren.Cotton at ses-astra.com <Darren.Cotton at ses-astra.com> wrote:
Thanks Henrik,
I just having one small problem now - I can't send the data I get to hobbit....
Output of the bb query is: status server1.pusers green Wed Oct 3 12:40:00 UTC 2007\nConnected_Users : 175\n
DSLGWS="^server[12345]\$" RESULT=0 bb 212.56.225.37 "hobbitdboard host=${DSLGWS} test=pusers fields=msg" |
while read L do NBUSERS=echo "$L" | sed 's/.* //g' | sed 's/n//g'RESULT=expr $RESULT + $NBUSERSecho $RESULT doneecho $RESULT
$BB $BBDISP "status Total-Users.pusers green
dateConnected_Users : $RESULT "The first echo gives me the Total after each while/do ie. 186 370 527 677 839
but the second echo gives me 0. I've tried using export RESULT but can't seem to be able to get the RESULT outside of the while/do statement.
I've had the same problem occasionally. I don't know what the "proper" solution is, but this works for me:
RES=`bb 212.56.225.37 "hobbitdboard host=${DSLGWS} test=pusers
fields=msg" |
while read L
do
NBUSERS=\`echo "$L" | sed 's/.* //g' | sed 's/n//g'\`
RESULT=\`expr $RESULT + $NBUSERS\`
echo $RESULT
done`
echo $RES
I.e., enclose the whole while loop in backticks, and also escape all backticks within the outer set. *Anything* echoed inside the outer set of backticks becomes part of the value of $RES, which makes debugging tricky.
T'ain't pretty, but it works and it's all in shell...
Ralph Mitchell