Web lists-archives.com

Re: Adding Date & Time to a script's output log

People are so generous with their time.

I hadn't realised that spaces were sometimes semantically relevant.  (And I liked Nicolas's detox joke, well done.)

Thanks very much for all the advice.  I'm using webmail, and I cannot reply in thread to any one message (the inbound messages have been fetchmail'd to a dovecot system here), so I am sorry if this acknowledgement appears unthreaded. Apologies, too, for not having noticed that Suzanne's name had still been in the From record.  I've had this account for many years, and until now had always used it via direct authenticated smtp submission but, because of some connectivity problems here, I'd posted using the webmail user agent which does not display the from name on the composition screen.  I think it's fixed, now, we'll see.  For the record, I had sent my original message, not she.

Many thanks, again,

regards, Ron

----- Original Message -----
From: SUZANNE COBB <ronleach@xxxxxxxxx>
To: Debian Users <debian-user@xxxxxxxxxxxxxxxx>
Sent: Thu, 01 Jun 2017 14:26:00 -0000 (UTC)
Subject: Adding Date & Time to a script's output log

List, good afternoon,

I am using a script to check and update a dynamic IP address in our DNS records.  I have tried to add a date and time output to a log file which records IP address changes and updates - but the change I inserted is not working.  I think the problem is that I have not understood correctly how to capture the *text* of the date and time, and then add it to a script 'echo' output line.  May I show the two lines I am using?

I try to capture the date and time into a variable named 'dt':

dt= $(date '+%d/%m/%Y %H:%M:%S');

[please see there is a space between = and $, and between Y and %]

I then try to prepend the date and time text (which i anticipate is now in the variable 'dt') to a line (the rest of which does work), logging the actual IP address change and the domain that needed to change.

echo "%dt" "Changed ${DYN_DOMAIN} from ${registeredIp} to ${externalIp}" >> /var/log/updated-ddns.log

[The registeredIp and externalIp and Dyn_Domain elements are working fine.  This script is based on one provided by our DNS provider, because none of the packaged ddns scripts fully match the update scheme required by the provider.  The updates are working fine, when needed, and so is the log - but only recording the nature of the change, not the date/time it changed.]

My problem is only with the dt section.  I looked in the doc sections of the Debian installation and there are some scripting howtos etc, but they're fairly introductory and I didn't find one that introduced the notion of how to set a variable with some text, and then use it. This is the first time I've tried to assign some text, and I would think I'm missing something fundamental.  If anyone would care to comment, I'd be very pleased to understand why the date assignment, and its output on the logging line, is not working in the way that I had thought would happen.

Grateful for any comments,

regards, Ron