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

Last change on this file since 19547 was 19519, checked in by Daniela Dorner, 5 years ago
bugfixes
  • Property svn:executable set to *
File size: 6.7 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\|Connection' >> $schedulefile ; } 2>&1 )
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 if [ "$text" != "" ] || [ $check1 -gt 0 ]
45 then
46 printprocesslog "links -width 300 -ssl.certificates 0 -dump https://www.swift.psu.edu/operations/obsSchedule.php?d="$1" | grep "$1" >> "$schedulefile
47 printprocesslog "WARN could not get Swift schedule ("$text", return code: "$check1")"
48 echo "WARN could not get Swift schedule ("$text", return code: "$check1")"
49 if [ "$text" = "Connection timed out" ] || [ "$text" = "Connection refused" ]
50 then
51 printprocesslog "WARN could not connect to https://www.swift.psu.edu/operations/obsSchedule.php?d="$1
52 finish
53 fi
54 fi
55}
56
57
58for date in ${dates[@]}
59do
60 printprocesslog "INFO getting Swift schedule for the night of "$date
61 #echo "INFO getting Swift schedule for the night of "$date
62 # paths and files needed to store schedule
63 date2=`echo $date | sed -e 's/\//-/g'`
64 schedulepath=/home/factwww/scheduling/$date
65 if [ ! -d $schedulepath ]
66 then
67 printprocesslog "WARNING "$schedulingpath" does not exist."
68 echo "WARNING "$schedulingpath" does not exist."
69 continue
70 fi
71 schedulefile=$schedulepath/swift.schedule
72 schedulefile2=$schedulepath/swift.schedule.formated
73 schedulefile2old=$schedulepath/swift.schedule.formated.old
74 schedulefile3=$schedulepath/swift.schedule.txt
75 schedulefile4=$schedulepath/swift.schedule-cut.txt
76
77 # overwrite already existing file
78 echo "Schedule retrieved at "`date` > $schedulefile
79 # Get Swift Data
80 # for the date of sunset
81 printprocesslog "INFO Checking "$date2
82 #lynx -width 200 -nolist -dump https://www.swift.psu.edu/operations/obsSchedule.php?d=$date2 | grep $date2 >> $schedulefile
83 #links -width 300 -ssl.certificates 0 -dump https://www.swift.psu.edu/operations/obsSchedule.php?d=$date2 | grep $date2 >> $schedulefile
84 getschedule $date2
85 # for the date of sunrise
86 nextday=`date +%Y-%m-%d --date=$date2"+24hour"`
87 printprocesslog "INFO Checking "$nextday
88 #lynx -width 200 -nolist -dump https://www.swift.psu.edu/operations/obsSchedule.php?d=$nextday | grep $nextday >> $schedulefile
89 #links -width 300 -ssl.certificates 0 -dump https://www.swift.psu.edu/operations/obsSchedule.php?d=$nextday | grep $nextday >> $schedulefile
90 getschedule $nextday
91
92 # check if schedule is empty
93 #checkcontent=`cat $schedulefile`
94 #if [ "$checkcontent" = "" ]
95 #then
96 # printprocesslog "INFO No Schedule found for the night of "$date
97 # continue
98 #fi
99 numnotfound=`grep -c 'was not found' $schedulefile`
100 if [ $numnotfound -gt 1 ]
101 then
102 printprocesslog "INFO No Schedule found for the night of "$date
103 #echo "INFO No Schedule found for the night of "$date
104 continue
105 fi
106 if [ $numnotfound -eq 1 ]
107 then
108 printprocesslog "INFO No Schedule found half of the night ("$date")"
109 #echo "INFO No Schedule found half of the night ("$date")"
110 fi
111
112 # copy of formatted schedulefile for comparison
113 if [ -e $schedulefile2 ]
114 then
115 mv $schedulefile2 $schedulefile2old
116 fi
117 # grep only the columns which are needed
118 #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
119 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
120
121 # check if there is an update in the schedule
122 # return values of diff
123 # 0: no differences found
124 # 1: differences found
125 # >1: error
126 upd=""
127 if [ -e $schedulefile2old ]
128 then
129 diff $schedulefile2 $schedulefile2old >/dev/null
130 checkdiff=$?
131 if [ $checkdiff -eq 0 ]
132 then
133 printprocesslog "INFO Schedule did not change."
134 continue
135 else
136 update="(upd)"
137 fi
138 else
139 update="(new)"
140 fi
141
142 # output list of sources
143 echo -n "Searched the schedule for the following source names: " >$schedulefile3
144 for (( i=0; i<${#sources[@]}; i++ ))
145 do
146 echo -n ${sources[$i]} >>$schedulefile3
147 i2=`echo " $i + 1" | bc -l`
148 if [ $i2 -lt ${#sources[@]} ]
149 then
150 echo -n ", " >>$schedulefile3
151 else
152 echo "" >>$schedulefile3
153 fi
154 done
155
156 printprocesslog "INFO searching the Swift schedule for the following sources: "${sources[@]}
157 # search for source names in schedule file
158 for (( i=0; i<${#sources[@]}; i++ ))
159 do
160 grep "${sources[$i]}" $schedulefile2 >>$schedulefile3
161 done
162
163 # check if a source was found
164 numfound=`cat $schedulefile3 | wc -l`
165 if [ $numfound -eq 1 ]
166 then
167 echo -e "\nNone of the sources was found in the Swift schedule." >> $schedulefile3
168 else
169 echo "night of "$date": "$update && cat $schedulefile3 | grep -v Searched | sort
170 fi
171
172 # output link to full schedule
173 echo -e "\nThe full schedule can be found <a href='../scheduling/"$date"/"`basename $schedulefile2`"'>here</a>\n" >>$schedulefile3
174
175 printprocesslog "INFO schedule output stored to "$schedulefile3
176done
177
178finish
Note: See TracBrowser for help on using the repository browser.