From owner-freebsd-hackers Mon Jan 28 7:14:54 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from smtpproxy2.mitre.org (smtpproxy2.mitre.org [128.29.154.90]) by hub.freebsd.org (Postfix) with ESMTP id A3B7C37B416 for ; Mon, 28 Jan 2002 07:14:37 -0800 (PST) Received: from avsrv2.mitre.org (avsrv2.mitre.org [128.29.154.4]) by smtpproxy2.mitre.org (8.11.3/8.11.3) with ESMTP id g0SFEGc28171; Mon, 28 Jan 2002 10:14:16 -0500 (EST) Received: from MAILHUB1 (mailhub1.mitre.org [129.83.20.31]) by smtpsrv2.mitre.org (8.11.3/8.11.3) with ESMTP id g0SFEEi04355; Mon, 28 Jan 2002 10:14:14 -0500 (EST) Received: from dhcp-105-164.mitre.org (128.29.105.164) by mailhub1.mitre.org with SMTP id 8982072; Mon, 28 Jan 2002 10:13:36 -0500 Message-ID: <3C556AC3.AFB26074@mitre.org> Date: Mon, 28 Jan 2002 10:14:11 -0500 From: Jason Andresen Organization: The MITRE Corporation X-Mailer: Mozilla 4.75 [en]C-20000818M (Windows NT 5.0; U) X-Accept-Language: en MIME-Version: 1.0 To: dan@langille.org Cc: freebsd-hackers@freebsd.org Subject: Re: shell scripts that hang around forever References: <200201280119.g0S1JHD97804@lists.unixathome.org> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Dan Langille wrote: > > Folks: have a look at this FreshPorts shell script and let me know if > there is a better way to do this. > > This script waits for a file to arrive in a directory, then runs a scipt > to process it. It's part of FreshPorts. the procmail script spools the > incoming cvs-all message to a temporary location, then moves it to the > incoming directory. > > The lockfile is an attempt to make the script single-entry (only one > instance at a time). If fails because the only way to exit the script is > to terminate it... > > At present, this script runs within a screen session (that's the easiest > way to control it). This script is sort of like a daemon, and I'm tempted > to replace it with one. If it was a daemon, I'm sure that would be much > easier. Wouldn't the following change be helpful if you always ^C the script to stop it? > #!/bin/sh > > LOCKFILE=${HOME}/msgs/processing.lock > MSGSDIR=${HOME}/msgs/FreeBSD/incoming cleanup() { rm -rf ${LOCKFILE} exit } trap cleanup sighup sigint sigquit sigill sigabrt sigterm > lockfile -r 0 $LOCKFILE > RESULT=$? > #echo result='$RESULT' > if [ $RESULT = 0 ] > then > cd ${MSGSDIR} > while . > do > FILECOUNT=`ls | wc -l` > > if [ $FILECOUNT -ne 0 ] > then > ls | xargs -n 1 $HOME/scripts/test-freebsd-cvs.sh > fi > > sleep 1 > done > cleanup > fi -- \ |_ _|__ __|_ \ __| Jason Andresen jandrese@mitre.org |\/ | | | / _| Network and Distributed Systems Engineer _| _|___| _| _|_\___| Office: 703-883-7755 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message