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

Last change on this file since 18557 was 18474, checked in by Daniela Dorner, 9 years ago
improved logging
  • Property svn:executable set to *
File size: 3.1 KB
Line 
1#!/bin/bash
2
3
4source `dirname $0`/../Sourcefile.sh
5printprocesslog "INFO starting $0"
6
7# list of sources
8sources=( "Mrk 421" "Mkn 421" "1959" "V404" "0323" "Crab" "CRAB" "Mrk 501" "Mkn 501" )
9
10
11# get dates
12if [ "$certaindate" != "" ]
13then
14 getdates $certaindate
15else
16 if [ "$1" = "" ]
17 then
18 # get next 3 night
19 getdates +3
20 else
21 getdates $1
22 fi
23fi
24
25
26
27for date in ${dates[@]}
28do
29 printprocesslog "INFO getting Swift schedule for the night of "$date
30 echo "INFO getting Swift schedule for the night of "$date
31 # paths and files needed to store schedule
32 date2=`echo $date | sed -e 's/\//-/g'`
33 schedulepath=/home/factwww/scheduling/$date
34 if [ ! -d $schedulepath ]
35 then
36 printprocesslog "WARNING "$schedulingpath" does not exist."
37 echo "WARNING "$schedulingpath" does not exist."
38 continue
39 fi
40 schedulefile=$schedulepath/swift.schedule
41 schedulefile2=$schedulepath/swift.schedule.formated
42 schedulefile3=$schedulepath/swift.schedule.txt
43
44 # overwrite already existing file
45 echo "" > $schedulefile
46 # Get Swift Data
47 # for the date of sunset
48 printprocesslog "INFO Checking "$date2
49 lynx -width 200 -nolist -dump https://www.swift.psu.edu/operations/obsSchedule.php?d=$date2 | grep $date2 >> $schedulefile
50 # for the date of sunrise
51 nextday=`date +%Y-%m-%d --date=$date2"+24hour"`
52 printprocesslog "INFO Checking "$nextday
53 lynx -width 200 -nolist -dump https://www.swift.psu.edu/operations/obsSchedule.php?d=$nextday | grep $nextday >> $schedulefile
54
55 # check if schedule is empty
56 checkcontent=`cat $schedulefile`
57 if [ "$checkcontent" = "" ]
58 then
59 printprocesslog "INFO No Schedule found for the night of "$date
60 continue
61 fi
62
63 # grep only the columns which are needed
64 cat $schedulefile | sed -r -e 's/[0-9]{5}\ \ \ [0-9]{1,3}\ \ \ //' | grep -o -E '^\ \ \ \ 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
65
66 # output list of sources
67 echo -n "Searched the schedule for the following source names: " >$schedulefile3
68 for (( i=0; i<${#sources[@]}; i++ ))
69 do
70 echo -n ${sources[$i]} >>$schedulefile3
71 i2=`echo " $i + 1" | bc -l`
72 if [ $i2 -lt ${#sources[@]} ]
73 then
74 echo -n ", " >>$schedulefile3
75 else
76 echo "" >>$schedulefile3
77 fi
78 done
79
80 printprocesslog "INFO searching the Swift schedule for the following sources: "${sources[@]}
81 # search for source names in schedule file
82 for (( i=0; i<${#sources[@]}; i++ ))
83 do
84 grep "${sources[$i]}" $schedulefile2 >>$schedulefile3
85 done
86
87 # check if a source was found
88 numfound=`cat $schedulefile3 | wc -l`
89 if [ $numfound -eq 1 ]
90 then
91 echo -e "\nNone of the sources was found in the Swift schedule." >> $schedulefile3
92 fi
93
94 # output link to full schedule
95 echo -e "\nThe full schedule can be found <a href='../scheduling/"$date"/"`basename $schedulefile2`"'>here</a>\n" >>$schedulefile3
96
97 printprocesslog "INFO schedule output stored to "$schedulefile3
98done
99
100finish
Note: See TracBrowser for help on using the repository browser.