#!/bin/csh -f

# I would like nightly to run on Mondays even if Sunday's run is not
# finished if the delay is due to the koko being dumped.  The Monday
# history is useful in the future.

# daw; 5/20/13

# always do this for now; 10/1/18

switch (`uname -s``uname -r`)
case SunOS5*:
	breaksw
case Linux[23]*:
	breaksw
default:
	exec echo ${0}: does not run on `uname -s` `uname -r`
endsw

while($#argv)
	switch ("$1")
	case -d:
		set DEBUG = /bin/echo
#		shift
#		breaksw
# fall through to verbose
	case -v:
		set VERBOSE
		shift
		breaksw
	default:
		set DQ = '"'
		exec echo ${0}: "What do I do with $DQ$1$DQ?"
	endsw
end

#set VERBOSE			# watch this for a while

if (! $?DEBUG) set DEBUG
set HOST = `hostname | sed 's;\.[Rr][Uu][Tt][Gg][Ee][Rr][Ss]\.[Ee][Dd][Uu];;'`

#~watrous/netapp-dump-scheduled -y koko
#if ($status) then
#    if ($?VERBOSE) echo `date +%T` A dump of koko was not scheduled for yesterday "($HOST)"
#    exit
#else
#    if ($?VERBOSE) echo `date +%T` A dump of koko WAS scheduled for yesterday "($HOST)"
#endif

set HOST = `hostname | sed 's;\.[Rr][Uu][Tt][Gg][Ee][Rr][Ss]\.[Ee][Dd][Uu];;'`

set NPID = Batch/Nightly/pid.$HOST
if (-e $NPID) then
    echo `date +%T` Removing $NPID on $HOST
    $DEBUG /bin/rm -f $NPID
endif

set NNPID = /tmp/onetapp-nightly.koko.lock
if (! -e $NNPID) set NNPID = /tmp/onetapp-nightlyn.koko.lock
if (-e $NNPID) then
    echo `date +%T` Removing $NNPID on $HOST
    $DEBUG Sys/slido /bin/rm -f $NNPID
endif

set NNPID = /tmp/netapp-nightly.koko.lock
if (! -e $NNPID) set NNPID = /tmp/netapp-nightlyn.koko.lock
if (! -e $NNPID) set NNPID = /tmp/netapp-nightly.koko.lcsr.lock
if (! -e $NNPID) set NNPID = /tmp/netapp-nightlyn.koko.lcsr.lock
if (-e $NNPID) then
    echo `date +%T` Removing $NNPID on $HOST
    $DEBUG Sys/slido /bin/rm -f $NNPID
endif

set NN2PID = /tmp/netapp-nightly2.koko.lock
if (! -e $NN2PID) set NN2PID = /tmp/netapp-nightly2n.koko.lock
if (! -e $NN2PID) set NN2PID = /tmp/netapp-nightly2.koko.lcsr.lock
if (! -e $NN2PID) set NN2PID = /tmp/netapp-nightly2n.koko.lcsr.lock
if (-e $NN2PID) then
    echo `date +%T` Removing $NN2PID on $HOST
    $DEBUG Sys/slido /bin/rm -f $NN2PID
endif

if ($?VERBOSE) echo `date +%T` Done
