#!/bin/tcsh

# By nerses replacing perl

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Author:   Krister Bruhwel 
# started:  December 2001
# modified: adapted for Hall D by Hovanes.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# This script uses a pipe to ps -ef, and then greps for alh.Config.  
# If the program is running, we do nothing.   However, if the program 
# is not running we check to see if curlyjoe has a windows manager up,
# and then start it.  It is ment to be called via cron.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
source ~/.cshrc
#source ~/.login

ps -eopid,args | grep alh | grep 'pager.alhConfig' | grep -v grep >/dev/null
# nothing must be in between these lines
if ( $? == 0 ) then
    echo "pager.alhConfig is running: "`date`
else
    echo "pager.alhConfig is not running, starting it : "`date`
    setenv DISPLAY ":0.0"
    setenv EPICS_CA_ADDR_LIST "129.57.255.4 129.57.57.188 129.57.99.255 129.57.191.255 129.57.68.97 129.57.36.123"

	# Check to see if a windows manager is running on curlyjoe.
	# If theres no manager, we can't pop our program, and nobody
	# gets paged.  A lesson learned due to a power outage in the CH.


    echo DISPLAY = $DISPLAY

    cd ${APP}/pagerApp/alh
    alh -s -m 200000 pager.alhConfig &
# nothing must be in between these lines
    if( $? == 0 ) then
	echo "... [started program]"
    else
	echo "ERROR: no dtsession on curlyjoe, can't pop a window."
	echo `pageOnCall.pl -message -m "cannot open handler display on curlyjoe"` 
    endif

endif
