From owner-freebsd-questions@FreeBSD.ORG Fri May 14 05:26:27 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0DD0116A4CE for ; Fri, 14 May 2004 05:26:27 -0700 (PDT) Received: from mta11.adelphia.net (mta11.adelphia.net [68.168.78.205]) by mx1.FreeBSD.org (Postfix) with ESMTP id 1221243D31 for ; Fri, 14 May 2004 05:26:26 -0700 (PDT) (envelope-from Barbish3@adelphia.net) Received: from barbish ([67.20.101.71]) by mta11.adelphia.net (InterMail vM.5.01.06.08 201-253-122-130-108-20031117) with SMTP id <20040514122625.WGLY21898.mta11.adelphia.net@barbish>; Fri, 14 May 2004 08:26:25 -0400 From: "JJB" To: "Christopher Nehren" Date: Fri, 14 May 2004 08:26:24 -0400 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.6604 (9.0.2911.0) In-Reply-To: <20040514032151.GA11016@prophecy.dyndns.org> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 Importance: Normal cc: FreeBSD Questions List Subject: RE: perl pause or wait X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Barbish3@adelphia.net List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 14 May 2004 12:26:27 -0000 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).