2

I wrote a simple script in order to log the date and time of every Pi boot into a text file. I placed the script into /etc/rc.local in order to have it execute on boot.

Here's the script:

#!/bin/sh

FILEPATH=/home/pi/bootups.txt
DATE=$(date +"%m.%d.%y")
TIME=$(date +"%l:%M %P")

$(echo $DATE'\t'$TIME >> $FILEPATH)

I call the script in rc.local using this line:

/home/pi/countbootup.sh

After every Pi boot, the DATE and TIME variable never change. I end up with a text file looking like:

07.12.16    11:17pm
07.12.16    11:17pm
07.12.16    11:17pm

When I call the script on my own, the DATE and TIME update as expected.

3
  • Because the clock hasn't yet synchronized with an NTP server, the Pi does not have a real time clock. You could add one or wait for an NTP sync before logging the time.
    – Ron Beyer
    Jul 14, 2016 at 2:24
  • That makes complete sense. Is there any way to tell when the NTP has been synced, or to ensure that the script is called after that?
    – R. Llamado
    Jul 14, 2016 at 3:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.