A simple bash script for date correction after reboot

I wrote the following script to correct the clock value on my computer which has a non-functional/faulty motherboard clock. Since i don't have an offline Stratum 1 NTP server or Stratum 2 for that matter i had to find a way to keep an approximate datetime value on my computer.

#!/usr/bin/env bash

#this script requires superuser permissions in order to work
#t1 is saved time value on time_value.txt
#t2 is estimated time value
#t3 is seconds since unix epoch converted to iso-8601 time format

t1=' '

while read line;
do
    t1=$line
done < clockd.txt

t2=$(date +%s)
t3=$(date +'%F %T' -d "@$t1")

if [[ $t2 -lt $t1 ]];
then
        date --set="$t3"
        date --set='+150 seconds'

elif [[ $t2 -eq $t1 ]]; then
        date  --set='+150 seconds'
fi

Computers have a hardware clock on the motherboard which keeps time when the computer is off. When the computer boots, the BIOS activates the bootloader which performs a sequence of operations until the kernel is loaded into memory afterwhich the native operating system takes over control.

The operating system synchronizes the time value of the hardware clock with the system clock if it's not found the default date is read from the BIOS. The system clock acts the reference of all

@reboot   *   *    *    *   ~/timecheck.sh

Add the above line on root crontab so as to execute everytime at reboot

#!/usr/bin/env bash

(date +%s) > clockd.txt

Write the above line to a different file with and make it executable then add it to cron job so as to execute every 2 minutes i.e

*/2    *    *    *    *    ~/clockd.sh

This writes the timestamp to clockd.txt every 2 minutes so as to have minute like accuracy at reboots

Reference

1.network time protocol (rfc-editor.org/rfc/rfc1305.html)

2.*Network Time Protocol Version 4

EDIT: changed time_value.txt to clockd.txt which is read by the while loop

NB: This is only useful for reapeted reboots within short durations