Re: [SLUG] bash script problem

From: Ian C. Blenke (icblenke@nks.net)
Date: Wed Oct 05 2005 - 21:36:52 EDT


Ron Youvan wrote:
> Hi all:
>
> I am having a bit of trouble with a bash scripting problem,
> where I never expected it. (Slackware OS w/o the X window system)
> I have DOS text strings coming to me over a fiber optic circuit
> through a "IP serial server," ever 5 minutes I get one, 60 or so
> character lines, and every other time I get two such strings.
> (one source very 5 minutes, another every 10 minutes)
There are some good opensource utilities for this, like conserver. Over
the years I've logged various switches, routers, servers, and other odds
and ends using serial consoles. The most fun was writing a TL/1 "walker"
that would inventory SONET switches via TCP sessions and some creative
perl expect scripting.
> I need to create a new file every 24 hours and start appending
> these incoming strings into the new file.
> I want to name the files with the current date, so:
> "at" midnight the file: date +.+ log needs to be created,
> such as 12-25-05.log (for next Christmas) as an example.
> I can divert date's string into a file as a text string,
> but I haven't been able to create a file named from date.
You might look into logrotate if you want something to "rotate" your
logs on a nightly basis.

If you are writing the logging engine, however, it's probably best to
close and then re-open the logfile with the embedded date each time you
log something (if it's a low-volume logging application).
> man date says: "date - print or set the system date and time"
> It prints the system time, but getting it into a variable
> seems to be my problem.
> I have tried everything that I can think of including:
> touch < date (+formatting info)
You want to use $() or backticks `` around your date command:

    $ touch $(date +%Y-%m-%d.log)
or
    $ touch `date +%Y-%m-%d.log`

To set a variable, just use the same technique:

    LOGDATE=`date +%Y-%m-%d.log`

Viola. I think this is what you are looking for.

 - Ian C. Blenke <icblenke@nks.net> <ian@blenke.com> http://ian.blenke.com

-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS). Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 17:57:27 EDT