Make your Raspberry Pi keep time synced!

Standard

Condition) Internet connectivity

As Raspberry PI don’t have RTC module, the time will be incorrect while turned on.
Though the OS will try to sync time, it might not be sufficient because of tolerance from NTP daemon (will not fix the time if the difference is <1000 seconds, by default).

Alternatively, use cron to periodically sync time.

1. Contents of updatetime.sh (I stored in ~/, usually /home/pi)

#/bin/bash

sudo /usr/sbin/service ntp stop > /dev/null 2>&1
sudo /usr/sbin/ntpd -gq > /dev/null 2>&1
sudo /usr/sbin/service ntp start > /dev/null 2>&1

2. Change file mode to 755 (if your file directory is different, use that directory instead of ~/)

chmod 755 ~/updatetime.sh

3. type crontab -e, and append following line, and save.
(meaning ‘execute the script every 1 minute’)

*/1 * * * * /home/pi/updatetime.sh

4. Now, your PI will be keep time synced 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.