This just stores the higher numeric value of what's already stored or the first field of proc uptime. If nothing is there when the script is ran it will store the contents of field 1 of /proc/uptime. Note the file location /home/ed/.myuptime will need to be altered for your system.
I attempt no manipulation of the values simply storing the larger of the two. Any manipulation can be done by a display routine - something like your script.
Code:
#!/bin/bash
FLE="/home/ed/.myuptime"
if [[ -f "$FLE" ]]
then
OLD_UP=$(cat "$FLE")
else
OLD_UP=0
fi
NEW_UP=$(awk '{ print $1 }' /proc/uptime)
if [[ $(echo "$NEW_UP > $OLD_UP" | bc) -eq 0 ]]
then
NEW_UP=$OLD_UP
fi
echo "$NEW_UP" > "$FLE"
Hope this is useful to you.