#!/bin/csh -f
# secure the remote sight for the night by killing telrun with SIGTERM.
# if no telrun, use /tmp/Shutter

set exp = ":[0-9][0-9][ /\.]*telrun"
set pids = `ps -eaf | grep "$exp" | awk '{print $2}'`

if ($#pids < 1) then
    echo No telrun -- looking for telescoped
    set exp = ":[0-9][0-9][ /\.]*telescoped"
    set pids = `ps -eaf | grep "$exp" | awk '{print $2}'`
    if (($#pids < 1) then
	echo No telescoped either -- try to start it
	cd ~ccdoper/bin
	./telescoped
	sleep 2
    endif
    /bin/echo "Close" >> /tmp/Shutter &
    exit
endif

foreach p ($pids)
    kill -TERM $p
end
