source: trunk/DataCheck/Monitoring/CheckSwiftSchedule.sh@ 19518

Last change on this file since 19518 was 19499, checked in by Daniela Dorner, 7 years ago
bugfixes and added that it only sends email if there was an update to the schedule
  • Property svn:executable set to *
File size: 6.6 KB
Line 
1#!/bin/bash
2
3
4source `dirname $0`/../Sourcefile.sh
5printprocesslog "INFO starting $0"
6
7# list of sources
8sources=( "MRK 421" "Mrk 421" "Mkn 421" "Mkn421" \
9 "1959" "V404" \
10 "1H 0323+342" "RXJ0324.6+3410" "RGBJ0324+3410" "SWIFTJ0325.3-5916"
11 "Crab" "CRAB" \
12 "Mrk 501" "Mkn 501" \
13 "1ES 2344+514" "1ES2344+514" )
14
15# target ids:
16# http://www.swift.ac.uk/swift_live/index.php
17
18# 0323: 90415, 36533, 34137, 35372, 35630
19# http://www.swift.ac.uk/swift_live/doSimpleSearch.php?catname=swiftmastr&searchpos=1H+0323%2B342&searchrad=12&searchepoch=2000&getWhat=1&sortBy=_r&dandr=on&coordType=0&retEpoch=2000&retType=0&retWhere=1
20
21# Mrk421: 30352, 35014, 215769, 31202, 80050, 31540, 91137, 34228, tbc
22# http://www.swift.ac.uk/swift_live/doSimpleSearch.php?catname=swiftmastr&searchpos=Mrk+421&searchrad=12&searchepoch=2000&getWhat=1&sortBy=_r&dandr=on&coordType=0&retEpoch=2000&retType=0&retWhere=2
23
24# get dates
25if [ "$certaindate" != "" ]
26then
27 getdates $certaindate
28else
29 if [ "$1" = "" ]
30 then
31 # get next 3 night
32 getdates +3
33 else
34 getdates $1
35 fi
36fi
37
38
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
58
59for date in ${dates[@]}
60do
61 printprocesslog "INFO getting Swift schedule for the night of "$date
62 #echo "INFO getting Swift schedule for the night of "$date
63 # paths and files needed to store schedule
64 date2=`echo $date | sed -e 's/\//-/g'`
65 schedulepath=/home/factwww/scheduling/$date
66 if [ ! -d $schedulepath ]
67 then
68 printprocesslog "WARNING "$schedulingpath" does not exist."
69 echo "WARNING "$schedulingpath" does not exist."
70 continue
71 fi
72 schedulefile=$schedulepath/swift.schedule
73 schedulefile2=$schedulepath/swift.schedule.formated
74 schedulefile2old=$schedulepath/swift.schedule.formated.old
75 schedulefile3=$schedulepath/swift.schedule.txt
76 schedulefile4=$schedulepath/swift.schedule-cut.txt
77
78 # overwrite already existing file
79 echo "Schedule retrieved at "`date` > $schedulefile
80 # Get Swift Data
81 # for the date of sunset
82 printprocesslog "INFO Checking "$date2
83 #lynx -width 200 -nolist -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
86 # for the date of sunrise
87 nextday=`date +%Y-%m-%d --date=$date2"+24hour"`
88 printprocesslog "INFO Checking "$nextday
89 #lynx -width 200 -nolist -dump https://www.swift.psu.edu/operations/obsSchedule.php?d=$nextday | grep $nextday >> $schedulefile
90 #links -width 300 -ssl.certificates 0 -dump https://www.swift.psu.edu/operations/obsSchedule.php?d=$nextday | grep $nextday >> $schedulefile
91 getschedule $nextday
92
93 # check if schedule is empty
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
103 printprocesslog "INFO No Schedule found for the night of "$date
104 #echo "INFO No Schedule found for the night of "$date
105 continue
106 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
112
113 # copy of formatted schedulefile for comparison
114 if [ -e $schedulefile2 ]
115 then
116 mv $schedulefile2 $schedulefile2old
117 fi
118 # grep only the columns which are needed
119 #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
120 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
139
140 # output list of sources
141 echo -n "Searched the schedule for the following source names: " >$schedulefile3
142 for (( i=0; i<${#sources[@]}; i++ ))
143 do
144 echo -n ${sources[$i]} >>$schedulefile3
145 i2=`echo " $i + 1" | bc -l`
146 if [ $i2 -lt ${#sources[@]} ]
147 then
148 echo -n ", " >>$schedulefile3
149 else
150 echo "" >>$schedulefile3
151 fi
152 done
153
154 printprocesslog "INFO searching the Swift schedule for the following sources: "${sources[@]}
155 # search for source names in schedule file
156 for (( i=0; i<${#sources[@]}; i++ ))
157 do
158 grep "${sources[$i]}" $schedulefile2 >>$schedulefile3
159 done
160
161 # check if a source was found
162 numfound=`cat $schedulefile3 | wc -l`
163 if [ $numfound -eq 1 ]
164 then
165 echo -e "\nNone of the sources was found in the Swift schedule." >> $schedulefile3
166 else
167 echo "night of "$date": "$update && cat $schedulefile3 | grep -v Searched | sort
168 fi
169
170 # output link to full schedule
171 echo -e "\nThe full schedule can be found <a href='../scheduling/"$date"/"`basename $schedulefile2`"'>here</a>\n" >>$schedulefile3
172
173 printprocesslog "INFO schedule output stored to "$schedulefile3
174done
175
176finish
Note: See TracBrowser for help on using the repository browser.