Changeset 19499


Ignore:
Timestamp:
04/29/19 12:10:26 (6 years ago)
Author:
Daniela Dorner
Message:
bugfixes and added that it only sends email if there was an update to the schedule
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DataCheck/Monitoring/CheckSwiftSchedule.sh

    r19469 r19499  
    3737
    3838
     39function getschedule()
     40{
     41   text=`links -width 300 -ssl.certificates 0 -dump https://www.swift.psu.edu/operations/obsSchedule.php?d=$1 | grep $1'\|was not found' >> $schedulefile `
     42   #text=`links -width 300 -ssl.certificates 0 -dump https://www.swift.psu.edu/operations/obsSchedule.php?d=$1 | grep $1 >> $schedulefile `
     43   check1=$?
     44   #echo "check "$check1
     45   if [ "$text" != "" ] || [ $check1 -gt 0 ]
     46   then
     47      printprocesslog "links -width 300 -ssl.certificates 0 -dump https://www.swift.psu.edu/operations/obsSchedule.php?d="$1" | grep "$1" >> "$schedulefile
     48      printprocesslog "WARN could not get Swift schedule ("$text", return code: "$check1")"
     49      echo "WARN could not get Swift schedule ("$text", return code: "$check1")"
     50      if [ "$text" = "Connection timed out" ]
     51      then
     52         printprocesslog "WARN could not connect to https://www.swift.psu.edu/operations/obsSchedule.php?d="$1
     53         finish
     54      fi
     55   fi
     56}
     57
    3958
    4059for date in ${dates[@]}
     
    5372   schedulefile=$schedulepath/swift.schedule
    5473   schedulefile2=$schedulepath/swift.schedule.formated
     74   schedulefile2old=$schedulepath/swift.schedule.formated.old
    5575   schedulefile3=$schedulepath/swift.schedule.txt
    5676   schedulefile4=$schedulepath/swift.schedule-cut.txt
    5777   
    5878   # overwrite already existing file
    59    echo "" > $schedulefile
     79   echo "Schedule retrieved at "`date` > $schedulefile
    6080   # Get Swift Data
    6181   #   for the date of sunset
    6282   printprocesslog "INFO Checking "$date2
    6383   #lynx -width 200 -nolist -dump https://www.swift.psu.edu/operations/obsSchedule.php?d=$date2 | grep $date2 >> $schedulefile
    64    links -width 300 -ssl.certificates 0 -dump https://www.swift.psu.edu/operations/obsSchedule.php?d=$date2 | grep $date2 >> $schedulefile
     84   #links -width 300 -ssl.certificates 0 -dump https://www.swift.psu.edu/operations/obsSchedule.php?d=$date2 | grep $date2 >> $schedulefile
     85   getschedule $date2
    6586   #   for the date of sunrise
    6687   nextday=`date +%Y-%m-%d --date=$date2"+24hour"`
    6788   printprocesslog "INFO Checking "$nextday
    6889   #lynx -width 200 -nolist -dump https://www.swift.psu.edu/operations/obsSchedule.php?d=$nextday | grep $nextday >> $schedulefile
    69    links -width 300 -ssl.certificates 0 -dump https://www.swift.psu.edu/operations/obsSchedule.php?d=$nextday | grep $nextday >> $schedulefile
    70    # fixme: find out why sometimes second day is missing in file (probably just put online late)
     90   #links -width 300 -ssl.certificates 0 -dump https://www.swift.psu.edu/operations/obsSchedule.php?d=$nextday | grep $nextday >> $schedulefile
     91   getschedule $nextday
    7192
    7293   # check if schedule is empty
    73    checkcontent=`cat $schedulefile`
    74    if [ "$checkcontent" = "" ]
    75    then
     94   #checkcontent=`cat $schedulefile`
     95   #if [ "$checkcontent" = "" ]
     96   #then
     97   #   printprocesslog "INFO No Schedule found for the night of "$date
     98   #   continue
     99   #fi
     100   numnotfound=`grep -c 'was not found' $schedulefile`
     101   if [ $numnotfound -gt 1 ]
     102   then
    76103      printprocesslog "INFO No Schedule found for the night of "$date
     104      #echo "INFO No Schedule found for the night of "$date
    77105      continue
    78106   fi
     107   if [ $numnotfound -eq 1 ]
     108   then
     109      printprocesslog "INFO No Schedule found half of the night ("$date")"
     110      #echo "INFO No Schedule found half of the night ("$date")"
     111   fi
    79112   
     113   # copy of formatted schedulefile for comparison
     114   if [ -e $schedulefile2 ]
     115   then
     116      mv $schedulefile2 $schedulefile2old
     117   fi
    80118   # grep only the columns which are needed
    81119   #cat $schedulefile | sed -r -e 's/[0-9]{5,6}[\ ]{1,4}[0-9]{1,3}[\ ]{1,6}//' | grep -o -E '^[\ ]{1,20}20[1-9][0-9]-[01][0-9]-[0-3][0-9]\ [0-9][0-9]:[0-9][0-9]:[0-9][0-9]\ \ \ 20[1-9][0-9]-[01][0-9]-[0-3][0-9]\ [0-9][0-9]:[0-9][0-9]:[0-9][0-9]\ \ \ [A-Z1-4]([A-Za-z0-9][\ \.\+\-]?){3,20}' > $schedulefile2
    82120   cat $schedulefile | awk -v d1=$date2 -v d2=$nextday '{ if (($1 ~ d1 && $2 ~ /^18|^19|^20|^21|^22|^23/) || ( $1 ~ d2 && $2 ~ /^0/)) print $1" "$2" "$3" "$4" "$7" "$8" "$9}' | sed -r -e 's/[-]?[0-9]{1,3}[.][0-9]{5}$//' | sed -r -e 's/[-]?[0-9]{1,3}[.][0-9]{5}\ $//' > $schedulefile2
     121   
     122   # check if there is an update in the schedule
     123   # return values of diff
     124   #   0: no differences found
     125   #   1: differences found
     126   #  >1: error
     127   if [ -e $schedulefile2old ]
     128   then
     129      if diff $schedulefile2 $schedulefile2old >/dev/null
     130      then
     131         printprocesslog "INFO Schedule did not change."
     132         continue
     133      else
     134         update="(upd)"
     135      fi
     136   else
     137      update="(new)"
     138   fi
    83139   
    84140   # output list of sources
     
    109165      echo -e "\nNone of the sources was found in the Swift schedule." >> $schedulefile3
    110166   else
    111       echo "night of "$date": " && cat $schedulefile3 | grep -v Searched | sort
     167      echo "night of "$date": "$update && cat $schedulefile3 | grep -v Searched | sort
    112168   fi
    113169
Note: See TracChangeset for help on using the changeset viewer.