Help with Global Variable

Hi Guyz,

I have a requirement like, i have to run a script every hour to count the number of errors encountered.
At the end of the day, i need to send them the total number of errors, that have ocurred the entire day.

For eg. if 10 errors occurred for starting 1 hr, 5 for next 1 hr, so on.
Summarized mail needs to be send at the end of the day with the total errors occured (here 15).

How can i preserve this value of errors occured each hour, so as to get hold of total erorrs at EOD?
I want to have a Global variable that preserves this value each hour & finally prints this value when needed.

Thnx in advance.
:slight_smile:

You can store the value in a file, for example :

ErrorFile=./error_count
if [ -e $ErrorFile ]
then
   last_error_count=$(<$ErrorFile)
else
   last_error_count=0
fi
. . . .
error_count=10
. . . .
(( new_error_count=last_error_count+error_count ))
If EndOfDay 
then
   echo Total error count for the day : $new_error_count
   echo 0 > $ErrorFile
else
   echo $new_error_count > $ErrorFile
fi

Jean-Pierre.