#!/bin/tcsh -fx
#
# 01/13/03 48141  MSwam  original
# 04/20/04 48141  MSwam  e-mail operator log
# 05/12/04 48141  MSwam  e-mail when error exit occurs as well
# 10/20/04 51433  MSwam  change logging and catch stderr from update task
# 09/10/12 70213  MSwam  use tcsh
#
#----------------------------------------------------------------------
#
set all_is_well = 0  # exit status for success
set run_failed = 1   # exit status for failure

set delivery_num = `echo $OSF_DATASET | awk -F'_' '{print $2}'`
echo "Processing cdbs delivery number $delivery_num"
set subject = "Delivery $delivery_num"

cdbs_report.py $delivery_num | tee -a ${OUTPATH}/cdbs_report.${delivery_num}

cat ${OUTPATH}/cdbs_report.${delivery_num} | mailx -s "$subject" ${OPERATOR_MAIL_LIST}

if(($status) != 0) then
  print "Mailing cdbs report failed for delivery $delivery_num"
  exit ${run_failed}
endif 

exit ${all_is_well}
