From: Helmut Richter on
On Tue, 16 Feb 2010, Frank Seitz wrote:

> Helmut Richter wrote:
> > On Tue, 16 Feb 2010, Frank Seitz wrote:
>
> >>> ln -s foobar.log foobar[whateverthenewdayis]
> >>
> >> A symlink is obviously not a solution, because the file
> >> gets overwritten with every run.
> >
> > The other way would work:
> >
> > Every night:
> > rm foobar.log
> > ln -s foobar[whateverthenewdayis] foobar.log
>
> No, but a hardlink (ln without -s) or cp would do it.

The softlink works: when the program tries to open foobar.log, it opens
the linked-to file instead.

The hardlink does not work because one cannot create a hardlink to a
non-existent file. If hardlink, the sequence would have to be:

touch foobar[whateverthenewdayis]
rm foobar.log
ln foobar[whateverthenewdayis] foobar.log

--
Helmut Richter
From: Frank Seitz on
Helmut Richter wrote:
> On Tue, 16 Feb 2010, Frank Seitz wrote:
>> Helmut Richter wrote:
>>> On Tue, 16 Feb 2010, Frank Seitz wrote:
>>>>> ln -s foobar.log foobar[whateverthenewdayis]
>>>> A symlink is obviously not a solution, because the file
>>>> gets overwritten with every run.
>>> The other way would work:
>>>
>>> Every night:
>>> rm foobar.log
>>> ln -s foobar[whateverthenewdayis] foobar.log
>> No, but a hardlink (ln without -s) or cp would do it.
>
> The softlink works: when the program tries to open foobar.log, it opens
> the linked-to file instead.

You are right.

> The hardlink does not work because one cannot create a hardlink to a
> non-existent file. If hardlink, the sequence would have to be:
>
> touch foobar[whateverthenewdayis]
> rm foobar.log
> ln foobar[whateverthenewdayis] foobar.log

Yes. Maybe a mv would suffice.

Frank
--
Dipl.-Inform. Frank Seitz
Anwendungen f�r Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel

Blog: http://www.fseitz.de/blog
XING-Profil: http://www.xing.com/profile/Frank_Seitz2
From: Ted Zlatanov on
On Tue, 16 Feb 2010 10:29:27 -0500 Jarmo <jampe(a)darkbusstop.com> wrote:

J> I have a problem and I was hoping someone could help me. I have a program
J> that every time it runs it saves a log file with same name about the changes
J> it did on that particular run. Result is that old file gets overwritten and
J> lost. I would like to create "virtual file" so that every time foobar.log is
J> written I actually end up with a file that has date and time added to it.

J> In other words:
J> I run application that writes to "foobar.log" and I want the file actually
J> go to "~/foobarlogs/foobarYYYY-MM-DD-HH-MM-SS.log" instead.

J> I know I did something similar years ago with perl but my
J> programming/scripting skills are too rusty to accomplish it anymore on my
J> own. I would greatly appreciate the help.

You may want to just use the `logrotate' utility as part of your
application's startup. Much easier than symlinks and custom code.

Ted
From: J�rgen Exner on
Frank Seitz <devnull4711(a)web.de> wrote:
>J�rgen Exner wrote:
>> Jarmo <jampe(a)darkbusstop.com> wrote:
>>> I have a problem and I was hoping someone could help me. I have a program
>>> that every time it runs it saves a log file with same name about the changes
>>> it did on that particular run. Result is that old file gets overwritten and
>>> lost.[...]
>> Not a Perl solution but what about running a cron job at midnight which
>> does a
>> ln -s foobar.log foobar[whateverthenewdayis]
>
>A symlink is obviously not a solution, because the file
>gets overwritten with every run.

You are right, I misread the original question.

If the application is really this misbehaved, then the OP has a whole
slew of other problems, too, e.g. what happens if two instances of the
application are running concurrently? Will they both write into the same
log file, stepping on each other's feet and destroying whatever the
other instance just wrote?

I would strongly suggest to fix the application. Even embedding the call
into a wrapper script which renames the log file immediately as
suggested by others won't fix all problems.

jue