[Gllug] RE: [GLUG] Cron revisited

Alain Williams addw at phcomp.co.uk
Thu Oct 24 15:36:30 UTC 2002


On Thu, Oct 24, 2002 at 04:08:55PM +0100, Tethys wrote:
> 
> "Cain Hurwitz" writes:
> 
> >#!/bin/bash
> >
> >if [ ! -f /var/run/java.script.lock ]; then
> >        touch /var/run/java.script.lock
> >	/usr/local/jre1.3.1_04/bin/java -cp /apps/cf/htdocs/java_scheduler
> >WinForward >> /apps/cf/htdocs/java_scheduler/WinForward.log
> >Rm -rf /var/run/java.script.lock
> 
> That would work, but it's not self regulating. If it dies without
> removing the lock file, for example, then it won't run again until
> the lock is manually removed. Better would be something like:
> 
> 	#!/bin/sh
> 
> 	prog=`basename "$0"`
> 	pidfile="/var/tmp/$prog.pid"
> 
> 	if [ -r "$pidfile" -a -s "$pidfile" ]
> 	then
> 		pid=`head -1 "$pidfile"`
> 		kill -0 "$pid"
> 		if [ $? -eq 0 ]
> 		then
> 			echo "Process $prog is already running with PID $pid" 1>&2
> 			exit 1
> 		fi
> 	fi
> 
> 	/usr/local/jre1.3.1_04/bin/java -cp \
> 		/apps/cf/htdocs/java_scheduler WinForward \
> 		>> /apps/cf/htdocs/java_scheduler/WinForward.log &
> 
> 	echo $! > "$pidfile"

That last line should be:
	trap "rm -f $pidfile" 0		# Tidy up when we die
 	echo $$ > "$pidfile"

-- 
Alain Williams

#include <std_disclaimer.h>

-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list