Notifications
Clear all

[Mark Solved / Archieved] error in utilities.sh function get_network_timestamp()?

7 Posts
2 Users
0 Reactions
35 Views
(@arjenr)
Posts: 40
Trusted Member Customer
Topic starter
 

Both my wittypi 4 L3v7 have a utilities.sh file with the following function. The output from the curl command with google.com has date: written with lower case d, so the latter part of the command cannot do what it is rather obviously intended to do.

I'm not sure what the result of this apparent error has been, but to find out, I changed the code on the machine I am local to, as you can see below.

Not being a wizard with the more complicated features of bash, I didn't test the get_network_timestamp() function. I was curious as to the curl command and so I tested that only, which is when I found the 'oddity'.

get_network_timestamp()
{
if $(has_internet) ; then
# local t=$(curl -s --head $INTERNET_SERVER | grep ^Date: | sed 's/Date: //g')
# ar - 07-04-2026
local t=$(curl -s --head $INTERNET_SERVER | grep ^date: | sed 's/date: //g')
if [ ! -z "$t" ]; then
echo $(date -d "$t" +%s)
else
echo -1
fi
else
echo -1
fi
}

I would much appreciate comment on this find of mine, if you can spare the time. It is hard to imagine, how it would be inconsequential.

Perhaps google changed the output formatting, who knows.

 
Posted : 07/04/2026 2:39 am
(@arjenr)
Posts: 40
Trusted Member Customer
Topic starter
 

I tried to delete my post, as it is not quite true, but there’s no such possibility. 

the issue is that the output from Google.com is different for https and http. 
I tested with https whereas the script actually specifies http. 
Http outputs Date and https outputs date. 
So the script function is quite ok. 
To shield from changes google might make in their use of upper and lower case, one could use [Dd]ate in the latter part of the curl command. 

After posting my comment I saw a delete button in two places, but it didn’t do anything. Now those delete buttons are gone. 

 

 
Posted : 07/04/2026 7:43 am
(@admin)
Posts: 756
Member Admin
 

@arjenr You are actually correct about that. According to RFC standards, HTTP header field names are case-insensitive, meaning 'Date' and 'date' should be treated as identical.

Although we did not reproduce the issue you mentioned, we believe it could happen in reality, and our software should handle both uppercase and lowercase variations of the 'Date' field.

A new version of softare (V4.23) is released for fixing this, and it can be installed/updated now.

 
Posted : 07/04/2026 8:52 am
(@arjenr)
Posts: 40
Trusted Member Customer
Topic starter
 

@admin

pi@PiHole3:~ $ curl -s --head  https://google.com  | grep ^Date: | sed 's/Date: //g'
pi@PiHole3:~ $ curl -s --head  http://google.com  | grep ^Date: | sed 's/Date: //g'
Tue, 07 Apr 2026 07:17:28 GMT
pi@PiHole3:~ $ curl -s --head  http://google.com  | grep ^[Dd]ate: | sed 's/[Dd]ate: //g'
Tue, 07 Apr 2026 07:17:36 GMT
pi@PiHole3:~ $ curl -s --head  https://google.com  | grep ^[Dd]ate: | sed 's/[Dd]ate: //g'
Tue, 07 Apr 2026 07:17:43 GMT

The second form is as in utilities.sh of software version 4.21. Works as intended. The first line uses https and it fails.

I checked this function from version 4.23 and noticed you found a different way of doing the same 🙂

pi@PiHole3:~ $ curl -sI --connect-timeout 3  https://google.com  | grep -i "^Date:" | sed 's/Date: //Ig' | tr -d '\r'
Tue, 07 Apr 2026 07:24:03 GMT
pi@PiHole3:~ $ curl -sI --connect-timeout 3  http://google.com  | grep -i "^Date:" | sed 's/Date: //Ig' | tr -d '\r'
Tue, 07 Apr 2026 07:24:53 GMT

Maybe it's not 100% the same as with [Dd]. I will have to check.

 
Posted : 07/04/2026 9:28 am
(@arjenr)
Posts: 40
Trusted Member Customer
Topic starter
 

Posted by: @admin

A new version of softare (V4.23) is released for fixing this, and it can be installed/updated now.

Should I just copy the new files from GitHub to the raspberry Pi and reboot it?

 

 
Posted : 07/04/2026 9:42 am
(@arjenr)
Posts: 40
Trusted Member Customer
Topic starter
 

And change the permissions to 755, of course ...

 
Posted : 07/04/2026 10:15 am
(@admin)
Posts: 756
Member Admin
 

@arjenr

Posted by: @arjenr

Should I just copy the new files from GitHub to the raspberry Pi and reboot it?

Posted by: @arjenr

And change the permissions to 755, of course ...

You may choose the way that suits you the best. They are just BASH scripts and are easy to deal with.

 
Posted : 07/04/2026 10:32 am
Join Waitlist We will inform you when the product arrives in stock. Please leave your valid email address below.