[RndTbl] race conditions?

Mike Pfaiffer high.res.mike at gmail.com
Thu Jul 12 20:34:34 CDT 2012

On 12-07-12 07:59 PM, Adam Thompson wrote:
> I just wrote the following snippet to quickly rotate some log files.
> I know this runs without bound, that's acceptable and desirable in
> this case.  What I'm worried about is creating race conditions if
> this gets run from cron every minute...
> ###check if daemon has died### if daemon-is-dead; then
> L=mydaemon.log shopt -u failglob for i in $( ls -1r ${L}.[0-9]*
> 2>/dev/null ); do N=${i#$L.} M=$(( ${N} + 1 )) mv -n $i "${L}.${M}"
> done if [ -f ${L} ] ; then mv -n ${L} ${L}.1; fi restart-daemon fi
> Am I shooting myself in the foot here?  The obvious race condition is
> if two copies run simultaneously, but this is only for temporary
> debugging purposes.  If necessary, I'll change the cron job from
> every minute to every five minutes.  Even then, the '-n' option to
> GNU mv should protect me...? Does anyone have a safer way to do this
> sort of thing manually?  I don't want this logfile managed by
> logrotate(8).
> -Adam Thompson DMTS (Contractor) athompso at dmts.biz (204) 291-7950 -
> direct (204) 489-6515 - fax
> _______________________________________________ Roundtable mailing
> list Roundtable at muug.mb.ca
> http://www.muug.mb.ca/mailman/listinfo/roundtable

	Going to sound like a dumb answer... Why not check the ps list to see 
if there is more than one instance running. If not then you are good to 
go. Otherwise shut it down.


More information about the Roundtable mailing list