Hi,
I changed the script a bit and now it works,
The double bracket I have made into a simple one and replaced all -e with
"\n" at the end of the echo line.
At the end I changed the colour.
--
You received this message because you are subscribed to the Google Groups
"weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/weewx-user/92961244-69e2-4224-94ef-740148ec16d7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
#!/bin/bash
clear
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
#change this if your reporting interval is different as this will be used to calculate
#rainrate. (60 minutes / INTERVAL) * RAIN - which is entered later on
INTERVAL="5"
#The stuff below is for colours you have to use echo -e
RESTORE='\033[0m'
RED='\033[00;31m'
GREEN='\033[00;32m'
YELLOW='\033[00;33m'
BLUE='\033[00;34m'
PURPLE='\033[00;35m'
CYAN='\033[00;36m'
LIGHTGRAY='\033[00;37m'
LRED='\033[01;31m'
LGREEN='\033[01;32m'
LYELLOW='\033[01;33m'
LBLUE='\033[01;34m'
LPURPLE='\033[01;35m'
LCYAN='\033[01;36m'
WHITE='\033[01;37m'
DBUSER=root
DBPASS=putti
DBNAME=weewx
MYSQLUSER=root
MYSQLPASS=putti
echo This fixes the database if there are any wrong entries "\n"
#echo -e
#mysql -u$DBUSER -p$DBPASS --database=$DBNAME --execute="SHOW COLUMNS FROM archive FROM $DBNAME;"
echo If you just press enter for the next two prompts you will get all the rainfall for the day "\n"
#echo -e
echo Input the date in this format: ${LRED} 'YYYY-MM-DD' ${RESTORE}"\n"Press enter for the current date: "\n"
read INDATE
#if the date is not entered then default to the current year
if [ -z "$INDATE" ]
then
INDATE=`date +%F`
#echo $INDATE
fi
#echo $INDATE
echo The date selected is ${LBLUE} $INDATE ${RESTORE} "\n"
#echo -e
echo Input the time you want to find in this format: ${LRED} 'HH:MM:SS' ${RESTORE}"\n"Press enter to select midnight: "\n"
read INTIME
#if the date is not entered then default to the current year
if [ -z "$INTIME" ]
then
INTIME="00:00:00"
fi
echo The time selected is ${LBLUE} $INTIME ${RESTORE}"\n"
#echo -e
echo Input the rain amount you want to change in this format: ${LRED} 'MM.M' ${RESTORE}"\n"Press enter to select zero: "\n"
read RAIN
#if the rain is not entered then default to zero
if [ -z "$RAIN" ]
then
RAIN="0"
fi
#echo -e
echo The rain amount is ${LBLUE} $RAIN ${RESTORE} and the reporting interval is ${LBLUE} $INTERVAL ${RESTORE} minutes.
#echo -e
RAINRATE=$((60 / INTERVAL))
RAINRATE=$(echo "$RAINRATE * $RAIN" | bc)
#if the rainrate is not entered then default to .001 so my logic to check for zero still works
#and I can redo the rain if needed. Otherwise I don't see any records because they are zero
if [ "$RAINRATE" = "0" ]
then
RAINRATE="0.001"
fi
FINDDATE=`date -d "$INDATE $INTIME" +%s`
echo The epoch date you want to find in the list below is ${LBLUE} $FINDDATE ${RESTORE} "\n"
#echo -e
#need to find the next day epoch time in case this program is run for a date in the past otherwise it
#will show all the rain entries on the screen and not just one days worth
NEXTDAY=$(($FINDDATE+86400))
echo Next day epoch date is: ${LBLUE} $NEXTDAY ${RESTORE} "\n"
MIDNIGHTTIME=`date -d "$INDATE 00:00:00" +%s`
echo Midnight time is: ${LBLUE} $MIDNIGHTTIME ${RESTORE} "\n"
#echo -e
#show the rain for the date selected
#echo -e ${LBLUE}
mysql -u$DBUSER -p$DBPASS --database=$DBNAME -e "select dateTime, rain, rainRate from archive where (rainRate > 0 and dateTime <= $NEXTDAY and dateTime >= $MIDNIGHTTIME);"
#echo -e ${RESTORE}
echo Rain value is: ${LBLUE} $RAIN ${RESTORE} and rain rate value is: ${LBLUE} $RAINRATE ${RESTORE} "\n"
echo If there are no records above then that means there are no rain rates for ${LRED} $INDATE $INTIME ${RESTORE} "\n"
#echo -e
echo Select the first and last record you want updated
echo Usually pick the first record with rain and then the records below it that have rain rates
echo but do not have rain records. Hope that makes sense."\n"
#echo -e
read -p "Select the FIRST dateTime you want to update: " FIRSTREC
echo The FISRT date you chose is ${LBLUE} `date -d@$FIRSTREC` ${RESTORE}"\n"
#echo -e
read -p "Select the LAST dateTime you want to update: " LASTREC
echo The LAST date you chose is ${LBLUE} `date -d@$LASTREC` ${RESTORE}"\n"
#echo -e
echo ${LRED}This is the Rain total and will be deleted"\n"
mysql -u$DBUSER -p$DBPASS --database=$DBNAME -e "select * from archive_day_rain WHERE (maxtime >= $FIRSTREC and maxtime <= $LASTREC);"
#echo -e
echo this is the rain rate and will be deleted "\n"
mysql -u$DBUSER -p$DBPASS --database=$DBNAME -e "select * from archive_day_rainRate WHERE (dateTime = $MIDNIGHTTIME);"
#echo -e ${RESTORE}
echo The rain amount selected is ${LBLUE} $RAIN ${RESTORE}"\n"
echo The Rain rate will be calculated as: ${LBLUE} $RAINRATE ${RESTORE}"\n"
#echo -e
echo Press y to update the database:"\n"
while true; do
echo The changes will take effect if you press y. Press CTRL-C to cancel updates.
read -p "Do you wish to update the database?" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
echo "\n"
echo Stop weewx"\n"
/etc/init.d/weewx stop
echo Back up database to /tmp
if ! /usr/bin/mysqldump --user=$MYSQLUSER --password=$MYSQLPASS $DBNAME > /tmp/weewx-$(date +%F-%T).sql ; then
clear
echo Backup failed. Do not contiune as data will be changed after this point
echo Starting weewx
/etc/init.d/weewx start
exit 1
fi
echo then set the data to 0
#have to zero out all the selected records and then update ONLY the first selected record or the
#rain records will be duplicated. SO LEAVE THE 2 LINES BELOW AS IS!
mysql -u$DBUSER -p$DBPASS --database=$DBNAME -e "UPDATE archive SET rain=0 WHERE (dateTime >= $FIRSTREC and dateTime <= $LASTREC);"
mysql -u$DBUSER -p$DBPASS --database=$DBNAME -e "UPDATE archive SET rainRate=0.1 WHERE (dateTime >= $FIRSTREC and dateTime <= $LASTREC);"
mysql -u$DBUSER -p$DBPASS --database=$DBNAME -e "UPDATE archive SET rain=$RAIN WHERE (dateTime = $FIRSTREC);"
mysql -u$DBUSER -p$DBPASS --database=$DBNAME -e "UPDATE archive SET rainRate=$RAINRATE WHERE (dateTime = $FIRSTREC);"
#mysql -u$DBUSER -p$DBPASS --database=$DBNAME -e "UPDATE archive SET rainRate=$RAINRATE WHERE (dateTime >= $FIRSTREC and dateTime <= $LASTREC) ;"
mysql -u$DBUSER -p$DBPASS --database=$DBNAME -e "DELETE from archive_day_rain where dateTime=$MIDNIGHTTIME;"
mysql -u$DBUSER -p$DBPASS --database=$DBNAME -e "DELETE from archive_day_rainRate where dateTime=$MIDNIGHTTIME;"
##echo If the yearly rainrate is wrong you can use the select statement below to delete the wrong entry
##echo "You can find the date and time on the yearly records."
##echo "'select * from archive_day_rainRate where maxtime = 1502098500;"
##echo "Then delete the entry"
mysql -u$DBUSER -p$DBPASS --database=$DBNAME -e "DELETE from archive_day_rainRate where maxtime=$MIDNIGHTTIME;"
echo ${LBLUE}
echo Number of records to process:"\n"
mysql -u$DBUSER -p$DBPASS << EOF
use $DBNAME;
select count(*) from archive;
EOF
echo ${RESTORE}
##echo then once that has been done you have to drop the daily stats usually only if data is corrupted
# wee_database /etc/weewx/weewx.conf --drop-daily
echo Rebuild the dailiy stats for the date $INDATE"\n"
wee_database /etc/weewx/weewx.conf --rebuild-daily --from=$INDATE --to=$INDATE
#wee_database /etc/weewx/weewx.conf --rebuild-daily --date=$INDATE
# wee_database /etc/weewx/weewx.conf --rebuild-daily
##echo if you want to delete data from the database you can use the delete from archive where dateTime < xxxxxxxxx;
##echo you then delete any NOAA files from /var/www/html/weather/NOAA
##echo then run the -drop-daily and rebuild-daily commands on hope it all works.
##echo start weewx again
##echo thats about it
echo Start weewx"\n"
/etc/init.d/weewx start
echo regenerate the web pages
wee_reports