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:[EMAIL PROTECTED]
Sent: Thursday, May 13, 2004 11:22 PM
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
>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
complete in that time. Hence, you should look into filesystem
functions: 'perldoc -f fcntl', 'perldoc -f flock', and 'perldoc -f

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
Granted, it's not traditional IPC, but architecting some IPC would
to guarantee that you're not processing the files before they're

Yet _another_ possible solution: why do you have four scripts? Can
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

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).

[EMAIL PROTECTED] mailing list
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Reply via email to