[Gllug] RE: [GLUG] Cron revisited

Tethys tet at accucard.com
Thu Oct 24 15:08:55 UTC 2002


"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"

Tet

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




More information about the GLLUG mailing list