-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_v5.sh
executable file
·211 lines (179 loc) · 5.4 KB
/
check_v5.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/bin/bash
# /work/opa/visir/operational_scripts/check_v5.sh > /work/opa/visir/operational_scripts/logs/check/check_v4_$(date +"%Y%m%d-%H%M").log &
##########################################
#
# Paths and routes
#
##########################################
echo "Source ~/.bash_profile"
source ~/.bash_profile
# paths
source $HOME/gutta.conf
LOG_PATH=$OP_PATH/logs/out
ERR_PATH=$OP_PATH/logs/err
##########################################
#
# Telegram configuration file
#
##########################################
# Notify 0 "Check" "2 message" # error message
# Notify 1 "Check" "3 message" # good message
##########################################
#
# Load utils
#
##########################################
echo "source ${OP_PATH}/utils.sh"
source ${OP_PATH}/utils.sh
echo "Little change"
# Find the last run
LASTRUN_LOGFILE=$(ls $LOG_PATH/runVisir*log -tr | tail -1)
LASTRUN=$(basename $LASTRUN_LOGFILE | cut -f 2 -d "_" | cut -f 1 -d ".")
echo " - Last run identified is : $LASTRUN"
##########################################
#
# Checks
#
##########################################
echo "Check script started now $(date)"
# Notify 2 "Check" "Script started now"
COMPONENTS=(campi tracce visual csv2shape copyToN08 GUTTA_n08)
# check if we already notified this job
if [[ -e ${LOG_PATH}/last_job_notified.log ]] ; then
LAST_NOTIFIED_JOB=$(cat ${LOG_PATH}/last_job_notified.log)
if [[ $LAST_NOTIFIED_JOB = $LASTRUN ]] ; then
echo " -- Job already notified"
exit
fi
fi
# check if all the components stopped running
for COMP in ${COMPONENTS[@]}; do
echo "Analyzing $COMP ..."
# log/err file names
LOG=$(find ${LOG_PATH} -name ${COMP}_${LASTRUN}_\* | head -n 1)
ERR=$(find ${ERR_PATH} -name ${COMP}_${LASTRUN}_\* | head -n 1)
echo "LOG file is $LOG"
echo "ERR file is $ERR"
if [[ ! -z "$LOG" ]] ; then
# get termination signals for the component
TermSig=$(grep "Terminated" $LOG | wc -l)
case $COMP in
"campi")
if [[ $TermSig -eq 1 ]]; then
echo "$COMP terminated"
else
echo "$COMP still to complete! Exiting..."
exit
fi
;;
"tracce")
if [[ $TermSig -eq 30 ]]; then
echo "$COMP terminated"
else
echo "$COMP still to complete! Exiting..."
exit
fi
;;
"visual")
if [[ $TermSig -eq 30 ]]; then
echo "$COMP terminated"
else
echo "$COMP still to complete! Exiting..."
exit
fi
;;
"csv2shape")
if [[ $TermSig -eq 1 ]]; then
echo "$COMP terminated"
else
echo "$COMP still to complete! Exiting..."
exit
fi
;;
"copyToN08")
if [[ $TermSig -eq 1 ]]; then
echo "$COMP terminated"
else
echo "$COMP still to complete! Exiting..."
exit
fi
;;
"GUTTA_n08")
if [[ $TermSig -eq 1 ]]; then
echo "$COMP terminated"
else
echo "$COMP still to complete! Exiting..."
exit
fi
;;
*)
echo "ELSE"
;;
esac
else
echo "------------------------------------------------------"
echo "LOG file not ready."
# JOBS=$(bjobs )#| wc -l)
# current_user=$(whoami)
# echo "Current user: $current_user"
JOBS=$(bjobs -o "JOB_NAME" -noheader | grep -v grep | wc -l )
JOBS_RUN=$(bjobs -o "STAT" -noheader | grep "RUN" | wc -l )
JOBS_PEND=$(bjobs -o "STAT" -noheader | grep "PEND" | wc -l )
echo "Running jobs are $JOBS_RUN"
echo "Pending jobs are $JOBS_PEND"
if [[ "$JOBS_RUN" -ge "1" ]] ; then
echo " -- Because job still in progress ($JOBS_RUN)"
exit
else
# if there are pending jobs, see the previous job if end SUCCESFULLY or NOT.
# IF PREV JOB END SUCCES -> wait
# IF PREV JOB END WITH EXIT -> send notify
if [[ "$JOBS_PEND" -ge "1" ]]; then
PREV_JOB=$(bjobs -a | tail -n 1 | grep "DONE" | wc -l)
if [[ "$PREV_JOB" -ge "1" ]] ; then
echo " -- Previous job ended succesfully, waiting the end of the pending jobs ($JOBS_PEND)."
exit
else
echo " -- Previous job ended with an error. Send notify."
echo "Let's see the components."
fi
else
echo " -- Because there are no jobs to do"
exit
fi
fi
fi
done
# check if all the components stopped running
for COMP in ${COMPONENTS[@]}; do
# log/err file names
LOG=$(find ${LOG_PATH} -name ${COMP}_${LASTRUN}_\* | head -n 1)
ERR=$(find ${ERR_PATH} -name ${COMP}_${LASTRUN}_\* | head -n 1)
echo "========"
echo "Parsing log files:"
echo $LOG
echo $ERR
echo "update ${LOG_PATH}/last_job_notified.log with $LASTRUN"
echo $LASTRUN > ${LOG_PATH}/last_job_notified.log
# do the analysis
echo " - Analysing component $COMP"
ERRORS_LINE=$(wc -l $ERR | cut -f 1 -d " ")
echo " - $COMP has $ERRORS_LINE lines in the file $ERR."
if [[ ! -z $ERRORS_LINE ]]; then
if [[ $ERRORS_LINE -gt 0 ]]; then
WARNING_TO_IGNORE=$(grep "imagick.so" $ERR | wc -l)
ERRORS_UPDATE=$(echo "$ERRORS_LINE - $WARNING_TO_IGNORE" | bc -l )
if [[ "$COMP"=="GUTTA_n08" ]] && [[ $ERRORS_UPDATE -eq 0 ]] ; then
echo " -- Errors are about imagick.so library so we can ignore!"
echo "update ${LOG_PATH}/last_job_notified.log with $LASTRUN"
echo $LASTRUN > ${LOG_PATH}/last_job_notified.log
else
echo " -- errors are real! MUST BE NOTIFIED"
echo "update ${LOG_PATH}/last_job_notified.log with $LASTRUN"
echo $LASTRUN > ${LOG_PATH}/last_job_notified.log
# Notify 0 "Check" "${COMP} has ${ERRORS_LINE} error lines [run: $LASTRUN]. Have a look!"
fi
fi
fi
done
echo "Finish check now $(date)"