[Top][All Lists]

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

Re: FWD: About Bash Script

From: Greg Wooledge
Subject: Re: FWD: About Bash Script
Date: Mon, 15 Feb 2010 17:04:01 -0500
User-agent: Mutt/

On Mon, Feb 15, 2010 at 10:20:05PM +0100, Mart Frauenlob wrote:
> > From:       Curt <address@hidden>

> > What I want to do is simply if the destination file exists, instead it 
> > creates an index number and appends that to the name.
> > 
> > If b.txt exists then a.txt will be renamed to b.txt.1, but if b.txt.1 
> > exists then it will be renamed to b.txt.2

Sounds like you're rotating logs.  I prefer multilog from daemontools
(http://cr.yp.to/daemontools.html) if it's a serious job.  If it's a
casual job, then I like to keep it nice and simple:

 mv b.txt.1 b.txt.2 >/dev/null 2>&1
 mv b.txt b.txt.1 >/dev/null 2>&1
 > b.txt
 chown someuser:somegroup b.txt
 chmod some-permission-string b.txt
 kill -HUP $(cat some-pid-file)
 # Or /some/daemon reload, whatever

Keeps a constant number of rotated backups, no complexity, no bashisms.

I suppose if you're a Linux user, you'll want to look at rotatelog (or
is it logrotate) instead, because that's more complex.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]