#

echo `date` > /ys/site/logs/monitor_auto_toban.log
# sleep 120
echo "*****"  >> /ys/site/logs/monitor_auto_toban.log
set extension = `date +%y%m%d`.`date +%H%M`

echo "Checking if a batch command file is waiting"
echo "Checking if a batch command file is waiting" >> /ys/site/logs/monitor_auto_toban.log
set at_files = `grep auto_toban /usr/spool/at/*`
if ($#at_files != 0) then
    echo "Found a batch command file.  Not re-submitting the job"
    echo "Found a batch command file.  Not re-submitting the job" >> /ys/site/logs/monitor_auto_toban.log
    exit	# it found a batch command file with a startup for AUTO_TOBAN
endif

echo "Checking if AUTO_BATCH is already running"
echo "Checking if AUTO_BATCH is already running" >> /ys/site/logs/monitor_auto_toban.log
set running = `ps -w | grep "idl_batch run_auto_toban"`
if ($#running <= 7) then	# run grep command return 7, so this condition is that it is not running
    # If it is not running, and no batch command file is waiting, then re-initialize and startup AUTO_TOBAN
    echo "No batch command file and not currently running.  Re-submitting the job"
    echo "No batch command file and not currently running.  Re-submitting the job" >> /ys/site/logs/monitor_auto_toban.log
    /ys/gen/script/idl_batch init_auto_toban /ys/site/logs/init_auto_toban$extension
    exit
endif

echo "AUTO_TOBAN is currently running"
echo "AUTO_TOBAN is currently running" >> /ys/site/logs/monitor_auto_toban.log


