#! /bin/bash

#==============================================================
#
#  Abs:  
#
#  Name: run_dupePVs_all.bash
#
#  Facility:  SLAC/LCLS
#
#  Auth: 07-Jul-2011, Jrock
#  Rev:  dd-mmm-yyyy, Reviewer's Name     (USERNAME)
#
#--------------------------------------------------------------
#  Mod:
#==============================================================

# Define LCLS_ROOT, based on AFS for development or NFS for production   
if [ -d /afs/slac/g/lcls ]; then 
   source /afs/slac/g/lcls/epics/setup/epicsReset.bash
else
   source /usr/local/lcls/epics/setup/epicsReset.bash
 
fi

cd /tmp
dupePVs_all.bash 

grep -v Logging ./duplicatePVNames.lst | grep -v CHECKING | grep -v "failed to open" | grep -v done | grep ": " > dupePVs_all.out

duplCount=`cat /tmp/dupePVs_all.out | wc -l`

if [ $duplCount -gt 0 ]; then
   echo $duplCount DUPLICATE PVs FOUND IN FACET AND LCLS IOCs: > /tmp/dupePVs_email.txt
   echo  >> /tmp/dupePVs_email.txt
   cat /tmp/dupePVs_all.out >> /tmp/dupePVs_email.txt
# DO NOT add zelazny to this email list!  Zelazny gets this email via controls-software-reports.
   cat /tmp/dupePVs_email.txt  | Mail -s "DUPLICATE PVs FOUND IN FACET AND LCLS IOCs" ppascual@slac.stanford.edu jingchen@slac.stanford.edu ernesto@slac.stanford.edu mshankar@slac.stanford.edu controls-software-reports@slac.stanford.edu
fi

# end of script
