The computers at our institute don’t have NTP installed, and the time
is rarely synchronized. The date on the computer I am writing this post
on is about half an hour behind. So here’s how you can get the correct
date from the terminal using wget, sed and the good ol’ date:
#!/bin/sh
# Prints the date.
x="$(wget -q -O - http://tycho.usno.navy.mil/cgi-bin/timer.pl | grep UTC | cut -c 5- | sed s/\,//g)"
date -d "${x}"
Put this file somewhere in your $PATH, make it executable and run it. It’ll print the
date in the local timezone. Here’s how it works:
- It gets the date from http://tycho.usno.navy.mil/cgi-bin/timer.pl and dumps it on the
terminal. - It gets the first line in UTC using grep
- It cuts out the
. - and removes the comma which causes date to choke
- Finally date -d converts the date into the local timezone and displays it.
I’ve this script running with watch -n 5 to give the date every five seconds in the terminal.
I’m sure the navy is thrilled about you hitting their server once every five seconds to get the time.