sean finney on 23 Sep 2009 00:16:12 -0700


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

Re: [PLUG] correct way to do this in bash


hi mag,

On Tue, Sep 22, 2009 at 07:35:06PM -0400, Mag Gam wrote:
> oh wow, SIGUSR1 sounds very complicated.

i suggest you give that a second consideration.  i don't think that it's
as complicated as you think it is :)

~ ~ ~ ~
#!/bin/bash

# catch USR1 to do some ad-hoc log rotation
trap newlog SIGUSR1

newlog(){
  ts="$(date +%Y%m%d.%H%M%S)"
  # redirect all stdout/stderr here
  exec >"data-${ts}.log" 2>"data-${ts}.err"
}

# first time redirection setup
newlog

/path/to/program
~ ~ ~ ~

and then just schedule a kill/pkill in your crontab (throwing your pid
into a seperate file at startup might be helpful for that as well).


	sean

Attachment: signature.asc
Description: Digital signature

___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug