#!/bin/sh
delay_sec="$1"
cmd="$2"
tnow=`date`
echo >> ~/log/ReRun.log "$tnow [$BASHPID] Starting for command \"$cmd\""
shift
while true
do
	eval "$cmd"

	tnow=`date`
	echo >> ~/log/ReRun.log "$tnow [$BASHPID] command \"$cmd\" exited"

	sleep "$delay_sec"

	ps -eo comm | grep > /dev/null -x omniNames

	if [ "$?" -ne 0 ]
	then
		tnow=`date`
		echo >> ~/log/ReRun.log "$tnow [$BASHPID] omniNames not detected, restarting the system"
		sudo shutdown -r now
	else
		tnow=`date`
		echo >> ~/log/ReRun.log "$tnow [$BASHPID] restarting command \"$cmd\""
	fi
done

