Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 14 May 2004 08:26:24 -0400
From:      "JJB" <Barbish3@adelphia.net>
To:        "Christopher Nehren" <apeiron@comcast.net>
Cc:        FreeBSD Questions List <questions@freebsd.org>
Subject:   RE: perl   pause or wait
Message-ID:  <MIEPLLIBMLEEABPDBIEGKECBFOAA.Barbish3@adelphia.net>
In-Reply-To: <20040514032151.GA11016@prophecy.dyndns.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Generally I agree with you assertion about coding file locking, but
in this case where newsyslog is rotating the log, there is already
an .0 file. Newsyslog does mv command to rename log.2 to log 3, then
log.1 to log.2, and log to log.1 finishing with touch log to create
the new empty one. So doing file lock on log.0 does not guarantee I
have the new rotated log.0. Using sleep 10 allows enough time for
newsyslog to do it's rotating of all the logs no matter how deep
they go.

Now could always first check the current log.0 file for size &
creation date, then do the newsyslog command, then interrogate the
log.0 file until it's file size & date is different as an method to
determine the log.0 file is the previous log file. But in my book
this is to much busy work for something that sleep 10 will do for
me. And besides my perl coding ability is not that good to code an
routine to perform that. Then on the other hand, I would accept an
working routine to add to my script to do that.

-----Original Message-----
From: Christopher Nehren [mailto:apeiron@comcast.net]
Sent: Thursday, May 13, 2004 11:22 PM
To: JJB
Cc: FreeBSD Questions List
Subject: Re: perl pause or wait

JJB wrote:
>I have perl script that issues the newsyslog command followed by 3
>perl scripts that process the new .0 rotated file.
>
>Problem is the newsyslog rotate has not completed creating the new
>.0 and rolling through the other .x files before the first perl
>script in trying to open the .0 file for processing.
>
>Is there in perl pause or wait command I can use to  allow some
time
>to elapse before continuing with the launch of the next script?

Using a statement that delays for a specified period of time is a
generally bad idea because you can't guarantee that the operation
will
complete in that time. Hence, you should look into filesystem
locking
functions: 'perldoc -f fcntl', 'perldoc -f flock', and 'perldoc -f
lock'.

Alternatively, you could use the four-argument form of select to
receive information about when the files are available, but that's
probably too complicated for what you want to do.

Reading through 'perldoc perlipc' is advised for what you want to
do.
Granted, it's not traditional IPC, but architecting some IPC would
help
to guarantee that you're not processing the files before they're
ready.

Yet _another_ possible solution: why do you have four scripts? Can
you
not do what you want with one well-structured script? Perl has
virtually all of the branching constructs of C, and some of its very
own.

--
I abhor a system designed for the "user", if that word is a coded
pejorative meaning "stupid and unsophisticated".  -- Ken Thompson
-
Unix is user friendly. However, it isn't idiot friendly.
-
Please CC me in all replies, even if I'm on the relevant list(s).



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?MIEPLLIBMLEEABPDBIEGKECBFOAA.Barbish3>