#!/bin/bash # index.html pie chart UP data. #Declare array, reset vars. declare -a VALUE declare -a LEDGEND COUNT=0 T4=0 #Open file for reading to array while read LINE; do T1=${LINE#*up } T2=${T1%,* user*} MIN=${T2#*:} NMIN=${T2%:*} HOUR=${NMIN#*da* } DAY=${T2% da*} # handle exceptions # min if [ -z ${MIN#*min} ] ; then HOUR="00" T3=${T2% min} MIN=${T3##*, } [ ${#MIN} -lt 2 ] && MIN="0${T3##*, }" fi # no day if [ "$DAY" = "$T2" ] ; then DAY=00 fi #check if less than last value. NOW=$DAY$HOUR$MIN NOW=${NOW/ /0} if [ $NOW -ge $T4 ] ; then LM=${MIN#0} LH=${HOUR# } LD=$DAY T4=$NOW T5=$T2 else let VMINUTES=$LD*1440+$LH*60+$LM VALUE[$COUNT]="${VMINUTES}," LEDGEND[$COUNT]="\"$T5\"," ((COUNT++)) T4=$NOW fi # echo $DAY $HOUR $MIN done < "/var/www/upPoss.txt" # If last one is less then second last one then the second last values are placed twice, so need to set values once. LM=${MIN#0} LH=${HOUR# } LD=$DAY T5=$T2 let VMINUTES=$LD*1440+$LH*60+$LM*1 VALUE[$COUNT]=${VMINUTES} LEDGEND[$COUNT]="\"$T5\"" # echo Number of elements: ${#VALUE[@]} # echo array's content VDATA=${VALUE[@]} LDATA=${LEDGEND[@]} let PRECOUNT=($COUNT-1) # 0 ref, so -1 PRE=$(echo ${LEDGEND[$PRECOUNT]} | sed 's@"\(.*\)".*@\1@' | sed 's@:..@ hours@' | sed 's@ 1 hours@ 1 hour@' | sed 's@, 0 hours@@' | sed 's@,@ and@' ) if [ ${VALUE[$COUNT]} -ge 344039 ] ; then # Update if longest time. cat /var/www/index.html | sed "s@\(cron script.\).*attempt was@\1 This is the current record! Last attempt was@" > /tmp/index.html cat /tmp/index.html > /var/www/index.html fi if [ ${VALUE[$COUNT]} -le 60 ] ; then # change record after reset. REC=${VALUE[$PRECOUNT]/,/} if [ $REC -ge 344039 ] ; then cat /var/www/index.html | sed "s@cron script..*ast attempt@cron script. Current record is $PRE, last attempt@" > /tmp/index.html cat /tmp/index.html > /var/www/index.html fi fi #echo ${LEDGEND[$PRECOUNT]} cat /var/www/index.html | sed "s@\(Current record.*ast attempt was \)\(.*\)\(.
\)@\1$PRE\3@" | sed "s_\(.*piechart.*\[\)\(.*\)\(\]\)_\1$VDATA \3_" | sed "s_\(.*legend\:.*\[\)\(.*\)\(\]\)_\1$LDATA \3_" > /tmp/index.html cat /tmp/index.html > /var/www/index.html rm /tmp/index.html exit 0