#!/bin/sh # This script takes the last readings of the chilled water meters and the # electrcical meters and generates a printout of it: # define logging root # lg=/home/chris/BTUmetering lg=MAINPROGROOT # General header echo -e "Hello,\n\nthis is your friendly CQT utility consumption server. We proudly present \nthe latest readings of our utility meters. This summary shows the current\nreadings, last month's readings, and the difference for a given unit.\n" # some text for water meters: echo "Readings of the chilled water meters:" #logfilenamelist logroot=("AHU1" "AHU2" "AHU3" "AHU4" "AHU5" "AHU6" "PCW2" "S14L3") logfile=$lg/log/summaryfile # header line echo -e "Unit\tMM/DD/YY-hh:mm:ss\tLast date\tnew kWh\told kWh\tconsumption" # go through the list totalwater=0 for unit in ${logroot[@]} do t=($(grep $unit $logfile |tail -n 1 2>/dev/null )) u=$? if (($u == 0)) then olddate=t[3] newdate=t[1] newtime=t[2] oldread=t[5] newread=t[4] diffread=t[6] echo -e "$unit\t${t[1]}-${t[2]}\t${t[3]}\t${t[4]}\t${t[5]}\t${t[6]}" else echo -e "$unit\t No data available" fi done #echo "Total heat removed by chilled water: $totalwater kWh" echo echo "From the reading of the electrical meters:" # serial number list of Landis&GYR measurement units. adrlist=("94529479" "94529480" "94529485" "94529481" "94529484" "94529486" "94529482" "94529487" "94529483" "94529488" "99828529" "99828528" "38751745" "38751742" "40183481") loglist=("MDB1" "MDB6E" "EAHU1" "MDB2" "MDB7E" "EAHU2" "MDB3" "EAHU3" "MDB4" "EAHU4" "MDB6" "EAHU6" "MDB14" "EAHU14" "MDB14E") echo -e "Unit\tSerial # \tMM/DD/YY-hh:mm:ss\tLast date\tnew kWh\told kWh\tconsumption" for (( i=0 ; $i<${#loglist[*]} ; i++)) do adr=${adrlist[$i]} unit=${loglist[$i]} logfile=$lg/log/e_summaryfile t=($(grep "$unit " $logfile |tail -n 1 2>/dev/null )) u=$? if (($u == 0)) then # sequence: olddate, nwdate, newtime, oldread, newread, diffread echo -e "$unit\t$adr\t${t[1]}-${t[2]}\t${t[3]}\t${t[4]}\t${t[5]}\t${t[6]}" else echo -e "$unit\t No data available" fi done echo -e "\nPlease note that the units MDB6E and MDB7E are different labels for E-MDB1 and E-MDB2.\nThese taps are supposedly connected to the emergency power supply lines in levels 1 and 2." echo -e "\nThis is an automatically generated email; please do not respond to this address, but feel\nfree to send any feedback to phyck@nus.edu.sg\n\nWith Best Regards,\n\nYour CQT utility server"