Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:11:46

0001 #!/bin/bash
0002 
0003 #setup vars
0004 
0005 IDIR=$1
0006 RUN_NUMBER=$2
0007 BS_CERT=$IDIR"/Certification_BS_run_"$RUN_NUMBER".txt"
0008 HARVESTING_FILE="bs_bad_ls_summary.harvest"
0009 HARVESTING_EXISTS=0
0010 HARVESTING_CREATED="bs_bad_ls_summary.created"
0011 
0012 #check if certification file found for this run
0013 if [ -f $BS_CERT ]
0014     then
0015     #all OK, check if the summary file exists
0016     if [ -f $HARVESTING_FILE ]
0017         then
0018         HARVESTING_EXISTS=1
0019     fi
0020 else
0021     if [ ! -f $HARVESTING_FILE ]
0022         then
0023         if [ ! -f $HARVESTING_CREATED ]
0024             then
0025             echo "harvesting creation date" > $HARVESTING_CREATED
0026         fi      
0027         exit
0028     fi
0029 fi
0030 
0031 #check if bad LS found in the currently processed run (0 = not found , >0 = found)
0032 #if yes, add to the summary file (if summary file does not exist, create one)
0033 
0034 if  [ -f $BS_CERT ]
0035     then
0036     ISBAD=`grep BAD $BS_CERT | wc -l`
0037     
0038     if [ "$ISBAD" -gt 0 ]
0039         then
0040         if [ "$HARVESTING_EXISTS" -eq 1 ]    
0041             then
0042 #check if run already saved in the summary file
0043             RUN_HARVESTED=`grep $RUN_NUMBER $HARVESTING_FILE | wc -l`
0044             if [ "$RUN_HARVESTED" -eq 0 ]
0045                 then
0046                 TEMP_FILE="cat.temp"
0047                 cat $HARVESTING_FILE $BS_CERT > $TEMP_FILE
0048                 echo "" >> $TEMP_FILE
0049                 mv $TEMP_FILE $HARVESTING_FILE
0050             fi
0051         else
0052             cp $BS_CERT $HARVESTING_FILE
0053             echo "" >> $HARVESTING_FILE
0054             if [ ! -f $HARVESTING_CREATED ]
0055                 then
0056                 echo "harvesting creation date" > $HARVESTING_CREATED
0057             fi
0058         fi
0059     fi
0060 fi
0061 
0062 
0063 #decide to send (or not yet) the email
0064 #if $SEND_EMAIL=0, do not send yet, if > 0 send (summary file older than x days
0065 SEND_EMAIL=`find $HARVESTING_CREATED -mtime +1 | wc -l`
0066 if [ "$SEND_EMAIL" -eq 0 ]
0067     then
0068     SEND_EMAIL=`find $HARVESTING_CREATED -mtime 1 | wc -l`
0069 fi
0070 
0071 if [ "$SEND_EMAIL" -gt 0 -a "$HARVESTING_EXISTS" -eq 1 ]
0072 #if [ "$SEND_EMAIL" -gt 0 ]
0073 then
0074     SUBJECT="Beamspot Bad LS Notification"
0075 # Email To ?
0076     #EMAIL="burkett@fnal.gov,Leonard.Spiegel@cern.ch,vimartin@fnal.gov,threus@cern.ch"
0077 #    EMAIL="threus@cern.ch"
0078 # Email text/message
0079     EMAILMESSAGE="bs_bad_ls_summary.email"
0080     cp $HARVESTING_FILE $EMAILMESSAGE
0081     echo "This is an automated email sent periodically and only if a run with a bad beamspot LS was identified." >> $EMAILMESSAGE
0082 # send email using /bin/mail
0083     /bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
0084     
0085 #need to delete the summary file after being sent
0086 
0087     rm $EMAILMESSAGE
0088     rm $HARVESTING_FILE
0089     
0090 #update date when last sent email (to send again in next x days)
0091     
0092     touch $HARVESTING_CREATED
0093     
0094 fi