[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

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


Reply to: