Re: Adding Date & Time to a script's output log
- Date: Thu, 1 Jun 2017 18:49:58 +0000 (UTC)
- From: davidson@xxxxxxxxxxxx
- Subject: Re: Adding Date & Time to a script's output log
On Thu, 1 Jun 2017, Nicolas George wrote:
Le tridi 13 prairial, an CCXXV, SUZANNE COBB a écrit :
I try to capture the date and time into a variable named 'dt':
dt= $(date '+%d/%m/%Y %H:%M:%S');
Note that %T is shorthand for %H:%M:%S
[please see there is a space between = and $, and between Y and %]
Well, fix it! This line executes the output of date as a command with
the dt environment variable set to an empty string. Variable
affectations do not have spaces around the equal.
Also, for scripting, you will want %Y-%m-%d, because it offers a lexical
If you go this convenient-lexical-order route, note that %F is
shorthand for %Y-%m-%d
And for maximum reliability, include the timezone or set it to
date +'%F %T %z'
Or simply translated to utc:
date -u +'%F %T'
That's all I got. Good luck with your project.