#!/bin/bash
#
## PROGRAM
# setiathome.cron.sh
#
## DESCRIPTION
# script to run (multiple) SETI@home binaries from the crontab
#
## COPYRIGHT
# copyright 2002 Wolfram Schlich <wolfram@schlich.org>
#
## CONFIGURATION
# change these to match your setup
SETIDIRS="$HOME/.setiathome/cpu0 $HOME/.setiathome/cpu1 "
SETIBIN="setiathome"
SETIBIN_ARGS="-nice 19 -proxy proxy.bla.fasel.org:3128"
UMASK="u=rw,g=,o="
## MAIN
for DIR in $SETIDIRS; do
	## check if SETI@home binary is executable
	if ! [ -x "$DIR/$SETIBIN" ]; then
		echo "* SETI@home ($DIR) binary not executable (maybe missing)!" >&2; exit 1
	## check if SETI@home binary is already running
	elif ps -p $(cat "$DIR/pid.sah") >/dev/null 2>&1; then
		echo "* SETI@home ($DIR) already running!"
	## ok, fire it up
	else
		cd "$DIR"; umask "$UMASK"; echo "* starting SETI@home ($DIR)";
		if ! $("./$SETIBIN" $SETIBIN_ARGS >/dev/null 2>&1 &); then
			echo "* cannot start SETI@home ($DIR)" >&2; exit 1
		fi
	fi
done