Bash script in How can I automatically update the hwclock with NTP when I have internet connection seems not to run as expected in Raspbian Stretch 9.4
The log file will be created with the first reading but no more readings will be appended to the file.
pi@raspberrypi:~$ ls -al hwc*
-rw-r--r-- 1 pi pi 84 Jul 31 18:40 hwcsynch.log
-rwxr-xr-x 1 pi pi 1783 Jul 31 18:39 hwcsynch.sh
crontab -e to have the script run every minute for testing purposes:
* * * * * /home/pi/hwcsynch.sh
Only the first reading is added to the file. Following readings will not.
pi@raspberrypi:~$ cat hwcsynch.log
Tue 31 Jul 18:40:02 CEST 2018: Connection to time-server. HwClock difference: 1 sec
And then run the bash script from prompt just to make sure it works:
pi@raspberrypi:~$ ./hwcsynch.sh
Connection to time-server
---------------------------------
HwClock: 1533055729 sec
SysClock: 1533055728 sec
---------------------------------
Difference: 1 sec
So I assume the script is running properly. Maybe it has to do with...?
if !(awk '/./{line=$0} END{print line}' $LOGFILE | grep -q "$msgConnection") || [ "$secDiff" -gt "$maxDiffSec" ]; then
echo $(date)": "$msgConnection". "$msgDiff >> $LOGFILE
fi
$msgConnection
,$secDiff
,$maxDiffSec
,$msgDiff
and$LOGFILE
defined?* * * * * /home/pi/hwcsynch.sh > /tmp/last_hwsync
in the crontab. It will give you the stdout of the script which will probably give a better understanding of what's going on.