Tuesday, August 05, 2014

Update NTP Via HTTP Google

I work behind Firewall
My Raspberry doesn't have clock hardware.

The problem is i set a crontab (schedule) but when the electricity down the timer reset to unwanted date time

here the script that do it every time hours for updating time

date -s "$(wget -S  "http://www.google.com/" 2>&1 | grep -E '^[[:space:]]*[dD]ate:' | sed 's/^[[:space:]]*[dD]ate:[[:space:]]*//' | head -1l | awk '{print $1, $3, $2,  $5 ,"GMT", $4 }' | sed 's/,//')"

or shorter code

 sudo date -s "$(curl -sD - google.com | grep '^Date:' | tr -d '\r,' | awk '{print $2, $4, $3, $6, $7, $5}')"