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

Last change on this file since 19478 was 19469, checked in by Daniela Dorner, 6 years ago
fixed bug
  • Property svn:executable set to *
File size: 4.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
39
40for date in ${dates[@]}
41do
42 printprocesslog "INFO getting Swift schedule for the night of "$date
43 #echo "INFO getting Swift schedule for the night of "$date
44 # paths and files needed to store schedule
45 date2=`echo $date | sed -e 's/\//-/g'`
46 schedulepath=/home/factwww/scheduling/$date
47 if [ ! -d $schedulepath ]
48 then
49 printprocesslog "WARNING "$schedulingpath" does not exist."
50 echo "WARNING "$schedulingpath" does not exist."
51 continue
52 fi
53 schedulefile=$schedulepath/swift.schedule
54 schedulefile2=$schedulepath/swift.schedule.formated
55 schedulefile3=$schedulepath/swift.schedule.txt
56 schedulefile4=$schedulepath/swift.schedule-cut.txt
57
58 # overwrite already existing file
59 echo "" > $schedulefile
60 # Get Swift Data
61 # for the date of sunset
62 printprocesslog "INFO Checking "$date2
63 #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
65 # for the date of sunrise
66 nextday=`date +%Y-%m-%d --date=$date2"+24hour"`
67 printprocesslog "INFO Checking "$nextday
68 #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)
71
72 # check if schedule is empty
73 checkcontent=`cat $schedulefile`
74 if [ "$checkcontent" = "" ]
75 then
76 printprocesslog "INFO No Schedule found for the night of "$date
77 continue
78 fi
79
80 # grep only the columns which are needed
81 #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
82 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
83
84 # output list of sources
85 echo -n "Searched the schedule for the following source names: " >$schedulefile3
86 for (( i=0; i<${#sources[@]}; i++ ))
87 do
88 echo -n ${sources[$i]} >>$schedulefile3
89 i2=`echo " $i + 1" | bc -l`
90 if [ $i2 -lt ${#sources[@]} ]
91 then
92 echo -n ", " >>$schedulefile3
93 else
94 echo "" >>$schedulefile3
95 fi
96 done
97
98 printprocesslog "INFO searching the Swift schedule for the following sources: "${sources[@]}
99 # search for source names in schedule file
100 for (( i=0; i<${#sources[@]}; i++ ))
101 do
102 grep "${sources[$i]}" $schedulefile2 >>$schedulefile3
103 done
104
105 # check if a source was found
106 numfound=`cat $schedulefile3 | wc -l`
107 if [ $numfound -eq 1 ]
108 then
109 echo -e "\nNone of the sources was found in the Swift schedule." >> $schedulefile3
110 else
111 echo "night of "$date": " && cat $schedulefile3 | grep -v Searched | sort
112 fi
113
114 # output link to full schedule
115 echo -e "\nThe full schedule can be found <a href='../scheduling/"$date"/"`basename $schedulefile2`"'>here</a>\n" >>$schedulefile3
116
117 printprocesslog "INFO schedule output stored to "$schedulefile3
118done
119
120finish
Note: See TracBrowser for help on using the repository browser.