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

Last change on this file since 18429 was 18421, checked in by Daniela Dorner, 10 years ago
added option to run script for more than one night and run it per default for the next 3 nights
  • Property svn:executable set to *
File size: 3.0 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 lynx -width 200 -nolist -dump https://www.swift.psu.edu/operations/obsSchedule.php?d=$date2 | grep $date2 >> $schedulefile
49 # for the date of sunrise
50 nextday=`date +%Y-%m-%d --date=$date2"+24hour"`
51 lynx -width 200 -nolist -dump https://www.swift.psu.edu/operations/obsSchedule.php?d=$nextday | grep $nextday >> $schedulefile
52
53 # check if schedule is empty
54 checkcontent=`cat $schedulefile`
55 if [ "$checkcontent" = "" ]
56 then
57 printprocesslog "INFO No Schedule found for the night of "$date
58 continue
59 fi
60
61 # grep only the columns which are needed
62 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
63
64 # output list of sources
65 echo -n "Searched the schedule for the following source names: " >$schedulefile3
66 for (( i=0; i<${#sources[@]}; i++ ))
67 do
68 echo -n ${sources[$i]} >>$schedulefile3
69 i2=`echo " $i + 1" | bc -l`
70 if [ $i2 -lt ${#sources[@]} ]
71 then
72 echo -n ", " >>$schedulefile3
73 else
74 echo "" >>$schedulefile3
75 fi
76 done
77
78 printprocesslog "INFO searching the Swift schedule for the following sources: "${sources[@]}
79 # search for source names in schedule file
80 for (( i=0; i<${#sources[@]}; i++ ))
81 do
82 grep "${sources[$i]}" $schedulefile2 >>$schedulefile3
83 done
84
85 # check if a source was found
86 numfound=`cat $schedulefile3 | wc -l`
87 if [ $numfound -eq 1 ]
88 then
89 echo -e "\nNone of the sources was found in the Swift schedule." >> $schedulefile3
90 fi
91
92 # output link to full schedule
93 echo -e "\nThe full schedule can be found <a href='../scheduling/"$date"/"`basename $schedulefile2`"'>here</a>\n" >>$schedulefile3
94
95 printprocesslog "INFO schedule output stored to "$schedulefile3
96done
97
98finish
Note: See TracBrowser for help on using the repository browser.