Maybe there is an easier way, but you could try putting your "variable" into a file.
An example: I turn my computer on and off as and when I need it, maybe several times a day.
I use ntpdate to sync my local time. I do not want to do this every boot-time, just once a day. I also wanted to play with cron
. So cron calls this script once an hour:
# No need to check the time more than once a day,
# no matter how often this script is called by cron
NOW=`date | cut -b 1-10`
if [ "$NOW" != "$LAST" ]; then
echo $NOW > /etc/.lasttimecheck
My "variable" is the date the time was last checked. It is held in the file .lasttimecheck
. If that is not today, the time is checked, and the file is updated.
Hope this helps.