In the need to add custom logging messages to ppp.log, I see that the date and time are missing when outputting the command to >> /var/log/ppp.log. Other pppd related messages in ppp.log are prepended with a timestamp format that is similar to: "Sat Apr 9 17:18:02 2016 : ". My goal is to output this exact date time format in a Mavericks shell script

I know that other log files have different date/time timestamps. I want to re-create the format as used in ppp.log.


This Mac OS X 10.9 environment is configured with a dutch language locale. Therefore $ echo $(date '+%a') returns "za" instead of the desired "Sat". That is the part that can be fixed by export LC_TIME="C" or export LC_TIME="POSIX". I have tried to read the date and pppd man page. However then there is still the abbreviated alphabetic timezone name CEST (the %Z part in $ date +%Z) in the output "Sat Apr 9 18:12:12 CEST 2016".

I know I can create the format using all the different $ date format codes, like %a %b %e etcetera. Though I guess there is a shorter way, isn't there?


After a lot of searching, a search for "date format without alphabetic time zone abbreviation" returned Info on ISO 8601, the date and time representation standard. That information helped me to find out that the timestamp format that is being used in Mavericks its /private/var/log/ppp.log file, is actually the ANSI C's asctime() format.

C asctime

To create C style asctime in a shell, a non English system might need to override the environment variable for time messages:

export LC_TIME="C"

And then there is the $ date formatting option %c that now displays local date time in the desired format:

$ date +%c
Sat Apr  9 21:10:20 2016

A tip when using echo date, do put the date between apostrophes echo "$(date +%c)", otherwise the filler space in single digit dates might be stripped from the output:

$ echo $(date +%c)
Sat Apr 9 21:13:57 2016
$ echo "$(date +%c)"
Sat Apr  9 21:14:30 2016

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .