OK thought I'd post my latest script which includes the error trap..I was 
occasionally getting a spike in my rrd trend however amended my script to try 
and trap the errors and pipe them to a txt file so I can read it.  Setting the 
variable to U (undefined) helps rrdtool trending ignore the value.  I now start 
my script with nohup thus if I pipe my error traps to nohup.out I get both any 
script errors internally generated and my text I send if I detect an error

I am a not a programmer, just a "simple" person who knows a handful of commands 
that gets by with...If you have any suggestion on handling errors better I'm 
all ears and for those that occasionally log bad data I hope this script may 
help you !


This is the errors since Friday, most of the errors even from previous running 
seemed to indicate that nothing has been returned from owserver thus a value is 
not printed out....however the error trap [-z] works great for the very 
occasional errors I get.  The error printed as "Data error on 
20.B71F05000000/volt.C
" is what the script send out automatically (which would normally go to 
/dev/null however starting a script with nohup script errors go to nohup.out) 
with the following line which has a date, the output of my [-z] error trap.

##### Error log ####
Fri Aug 17 16:55:48 EST 2007 -- 1Wire Data Collection Script Started -- 
Data error on 20.B71F05000000/volt.C
Mon Aug 20 17:22:45 EST 2007 Aquarium Temp error 
Mon Aug 20 17:47:44 EST 2007 Aquarium Temp error 40.6
Data error on 20.952A05000000/volt.D
Data error on 20.B71F05000000/volt.D
Tue Aug 21 18:51:43 EST 2007 ORP reading error 




#!/bin/bash
OWWRITE="/opt/bin/owwrite -s 3002"
OWREAD="/opt/bin/owread -s 3002"
AWK="/opt/bin/awk"
hwclock -s
echo "`date` -- 1Wire Data Collection Script Started -- " >>/public/nohup.out
while true
do
###  Force Simulataneous 1wire conversion ###
$OWWRITE simultaneous/voltage 1
$OWWRITE simultaneous/temperature 1

### Read 1wire data and convert into engineering units #PH=$($OWREAD 
20.B71F05000000/volt.A | $AWK '{printf "%4.2f\n",((($0-1)/1.6)+5.5)}')
US=$($OWREAD 20.B71F05000000/volt.B | $AWK '{printf "%5.1f\n",($0*100)}')
ORP=$($OWREAD 20.B71F05000000/volt.D | $AWK '{printf "%5.1f\n",($0*100)}')
TempAqua=$($OWREAD 20.B71F05000000/volt.C | $AWK '{printf 
"%3.1f\n",((($0-1)*5)+20)}')
LITRES=$($OWREAD 20.952A05000000/volt.D | $AWK '{printf 
"%3.1f\n",(($0-2.900)*60)}')
TempOut=$($OWREAD 28.11BF97000000/temperature | $AWK '{printf "%3.1f\n",($0)}')
TempAmb=$($OWREAD 28.D70598000000/temperature | $AWK '{printf "%3.1f\n",($0)}')
TempRes=$($OWREAD 28.A6EE97000000/temperature | $AWK '{printf "%3.1f\n",($0)}')
Accum_flow=$($OWREAD 1D.EBEF0900000034/counters.A | $AWK '{printf 
"%g\n",($0/4100)}')

### Out of Range Error trap -Do not log data ###
PHtest=`echo $PH |cut -f1 -d'.'`
if [ -z $PHtest ] || [ $PHtest -gt 7 ]; then
echo "`date` PH reading error $PH" >>/public/nohup.out
PH="U"
fi

ORPtest=`echo $ORP |cut -f1 -d'.'`
if [ -z $ORPtest ] || [ $ORPtest -gt 500 ]; then
echo "`date` ORP reading error $ORP" >>/public/nohup.out
ORP="U"
fi

UStest=`echo $US |cut -f1 -d'.'`
if [ -z $UStest ] || [ $UStest -gt 500 ]; then
echo "`date` Conductivity reading error $US" >>/public/nohup.out
US="U"
fi

TEMPtest=`echo $TempAqua |cut -f1 -d'.'`
if [ -z $TEMPtest ] || [ $TEMPtest -gt 33 ] ; then
echo "`date` Aquarium Temp error $TempAqua" >>/public/nohup.out
TempAqua="U"
fi

### Calculations based upon Data ###
C12=$(/opt/bin/awk -v PH="$PH" '{printf "%3.1f\n",((3*$0)*(10^(7-PH)))}' 
/public/kh_value.txt)
Todayflow=$(/opt/bin/awk -v AF="$Accum_flow" '{printf "%g\n",(AF-$0)}' 
/public/lastflow.txt)
Weekflow=$(/opt/bin/awk -v AF="$Accum_flow" '{printf "%g\n",(AF-$0)}' 
/public/weekflow.txt)

### Push Data into NEW Trend Files ###
rrdtool update /public/rrd/aqua_ph.rrd N:$PH
rrdtool update /public/rrd/aqua_orp.rrd N:$ORP
rrdtool update /public/rrd/aqua_temp.rrd N:$TempAqua:$TempRes
rrdtool update /public/rrd/aqua_co2.rrd N:$C12
rrdtool update /public/rrd/aqua_cond.rrd N:$US
rrdtool update /public/rrd/aqua_level.rrd N:$LITRES
rrdtool update /public/rrd/weather_temp.rrd N:$TempAmb:$TempOut
rrdtool update /public/rrd/aqua_waterchange.rrd N:$Todayflow:$Weekflow
sleep 90
done

Cheers  rob
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Owfs-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/owfs-developers

Reply via email to