Index: trunk/DataCheck/Monitoring/CheckSwiftSchedule.sh
===================================================================
--- trunk/DataCheck/Monitoring/CheckSwiftSchedule.sh	(revision 19496)
+++ trunk/DataCheck/Monitoring/CheckSwiftSchedule.sh	(revision 19499)
@@ -37,4 +37,23 @@
 
 
+function getschedule()
+{
+   text=`links -width 300 -ssl.certificates 0 -dump https://www.swift.psu.edu/operations/obsSchedule.php?d=$1 | grep $1'\|was not found' >> $schedulefile `
+   #text=`links -width 300 -ssl.certificates 0 -dump https://www.swift.psu.edu/operations/obsSchedule.php?d=$1 | grep $1 >> $schedulefile `
+   check1=$?
+   #echo "check "$check1
+   if [ "$text" != "" ] || [ $check1 -gt 0 ]
+   then
+      printprocesslog "links -width 300 -ssl.certificates 0 -dump https://www.swift.psu.edu/operations/obsSchedule.php?d="$1" | grep "$1" >> "$schedulefile 
+      printprocesslog "WARN could not get Swift schedule ("$text", return code: "$check1")"
+      echo "WARN could not get Swift schedule ("$text", return code: "$check1")"
+      if [ "$text" = "Connection timed out" ]
+      then
+         printprocesslog "WARN could not connect to https://www.swift.psu.edu/operations/obsSchedule.php?d="$1
+         finish
+      fi
+   fi
+}
+
 
 for date in ${dates[@]}
@@ -53,32 +72,69 @@
    schedulefile=$schedulepath/swift.schedule
    schedulefile2=$schedulepath/swift.schedule.formated
+   schedulefile2old=$schedulepath/swift.schedule.formated.old
    schedulefile3=$schedulepath/swift.schedule.txt
    schedulefile4=$schedulepath/swift.schedule-cut.txt
    
    # overwrite already existing file
-   echo "" > $schedulefile
+   echo "Schedule retrieved at "`date` > $schedulefile
    # Get Swift Data
    #   for the date of sunset
    printprocesslog "INFO Checking "$date2
    #lynx -width 200 -nolist -dump https://www.swift.psu.edu/operations/obsSchedule.php?d=$date2 | grep $date2 >> $schedulefile
-   links -width 300 -ssl.certificates 0 -dump https://www.swift.psu.edu/operations/obsSchedule.php?d=$date2 | grep $date2 >> $schedulefile
+   #links -width 300 -ssl.certificates 0 -dump https://www.swift.psu.edu/operations/obsSchedule.php?d=$date2 | grep $date2 >> $schedulefile
+   getschedule $date2
    #   for the date of sunrise
    nextday=`date +%Y-%m-%d --date=$date2"+24hour"`
    printprocesslog "INFO Checking "$nextday
    #lynx -width 200 -nolist -dump https://www.swift.psu.edu/operations/obsSchedule.php?d=$nextday | grep $nextday >> $schedulefile
-   links -width 300 -ssl.certificates 0 -dump https://www.swift.psu.edu/operations/obsSchedule.php?d=$nextday | grep $nextday >> $schedulefile
-   # fixme: find out why sometimes second day is missing in file (probably just put online late) 
+   #links -width 300 -ssl.certificates 0 -dump https://www.swift.psu.edu/operations/obsSchedule.php?d=$nextday | grep $nextday >> $schedulefile
+   getschedule $nextday
 
    # check if schedule is empty
-   checkcontent=`cat $schedulefile`
-   if [ "$checkcontent" = "" ]
-   then
+   #checkcontent=`cat $schedulefile`
+   #if [ "$checkcontent" = "" ]
+   #then
+   #   printprocesslog "INFO No Schedule found for the night of "$date
+   #   continue
+   #fi
+   numnotfound=`grep -c 'was not found' $schedulefile`
+   if [ $numnotfound -gt 1 ]
+   then 
       printprocesslog "INFO No Schedule found for the night of "$date
+      #echo "INFO No Schedule found for the night of "$date
       continue
    fi
+   if [ $numnotfound -eq 1 ]
+   then 
+      printprocesslog "INFO No Schedule found half of the night ("$date")"
+      #echo "INFO No Schedule found half of the night ("$date")"
+   fi
    
+   # copy of formatted schedulefile for comparison
+   if [ -e $schedulefile2 ]
+   then
+      mv $schedulefile2 $schedulefile2old
+   fi
    # grep only the columns which are needed
    #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
    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
+   
+   # check if there is an update in the schedule
+   # return values of diff
+   #   0: no differences found
+   #   1: differences found
+   #  >1: error
+   if [ -e $schedulefile2old ]
+   then
+      if diff $schedulefile2 $schedulefile2old >/dev/null 
+      then
+         printprocesslog "INFO Schedule did not change."
+         continue
+      else
+         update="(upd)"
+      fi
+   else
+      update="(new)"
+   fi
    
    # output list of sources
@@ -109,5 +165,5 @@
       echo -e "\nNone of the sources was found in the Swift schedule." >> $schedulefile3
    else
-      echo "night of "$date": " && cat $schedulefile3 | grep -v Searched | sort
+      echo "night of "$date": "$update && cat $schedulefile3 | grep -v Searched | sort
    fi
 
