source: palm/trunk/SCRIPTS/hlrn_watchdog @ 1046

Last change on this file since 1046 was 1046, checked in by maronga, 12 years ago

put scripts and utilities under GPL

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 6.2 KB
Line 
1#!/bin/ksh
2
3#--------------------------------------------------------------------------------#
4# This file is part of PALM.
5#
6# PALM is free software: you can redistribute it and/or modify it under the terms
7# of the GNU General Public License as published by the Free Software Foundation,
8# either version 3 of the License, or (at your option) any later version.
9#
10# PALM is distributed in the hope that it will be useful, but WITHOUT ANY
11# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License along with
15# PALM. If not, see <http://www.gnu.org/licenses/>.
16#
17# Copyright 1997-2012  Leibniz University Hannover
18#--------------------------------------------------------------------------------#
19#
20# Current revisions:
21# -----------------
22# code put under GPL (PALM 3.9)
23#
24# Former revisions:
25# -----------------
26# $Id: hlrn_watchdog 1046 2012-11-09 14:38:45Z maronga $
27#
28# 1029 2012-10-17 15:33:56Z maronga
29# Initial revision
30#
31# Description:
32# ------------
33# The hlrn_watchdog works for jobs on HLRN in Hannover/Berlin and with KDE.
34# It can be used for monitoring currently submitted jobs and will display
35# Running, Idle and Blocked jobs in a separate window, which is updated every
36# 10 minutes.
37# Starting: "hlrn_watchdog start <your hlrn username>"
38# Stopping: "hlrn_watchdog stop"
39#------------------------------------------------------------------------------!
40
41    cd $PALM_BIN
42
43    gate_h="hicegate.hlrn.de"
44    gate_b="bicegate.hlrn.de"
45    update_frequency=600
46
47#   trap strg+c
48    trap 'killall kdialog; exit' 2
49
50
51#   start/stop routine
52    if [[ $1 == "stop" ]]
53    then
54       result=`ps aux|grep -c "./hlrn_watchdog"`
55       if (( $result > 2 ))
56       then
57          result=`ps aux|grep -m1 "./hlrn_watchdog"`
58          killid=`echo $result | tr -s " " | cut -d" " -s -f2`
59          kill -9 $killid > /dev/null
60          killall kdialog
61          echo "*** hlrn_watchdog stopped."
62       else
63          echo "+++ hlrn_watchdog is not running."
64       fi
65       exit
66    elif [[ $1 == "start" ]]
67    then
68        result=`ps aux|grep -c "hlrn_watchdog"`
69        if (( $result > 2 ))
70        then
71           echo "+++ hlrn_watchdog is already running."
72        else
73           nohup ./hlrn_watchdog $2 1> /dev/null 2> /dev/null &
74           echo "\n*** hlrn_watchdog starting..."
75        fi
76        exit
77    else
78
79#      login via ssh and collect information in .watchdog_report.x
80       while true
81       do
82          ssh  $gate_h -l $1 "showq | egrep \"($1)\"" > .watchdog_report.x
83          ssh  $gate_b -l $1 "showq | egrep \"($1)\"" >> .watchdog_report.x
84
85          i=0
86          j=0
87          cat .watchdog_report.x|while read variable
88          do
89#            analyze output
90             comid[$i]=`echo $variable | tr -s " " | cut -d" " -s -f1`
91             jobid[$i]=`echo ${comid[$i]} | tr -s " " | cut -d"." -s -f2`
92             complex[$i]=`echo ${comid[$i]} | tr -s " " | cut -d"." -s -f1`
93             username[$i]=`echo $variable | tr -s " " | cut -d" " -s -f2`
94             status[$i]=`echo $variable | tr -s " " | cut -d" " -s -f3`
95             nodes[$i]=`echo $variable | tr -s " " | cut -d" " -s -f4`
96             walltime[$i]=`echo $variable | tr -s " " | cut -d" " -s -f5` 
97             day[$i]=`echo $variable | tr -s " " | cut -d" " -s -f6`   
98             month[$i]=`echo $variable | tr -s " " | cut -d" " -s -f7`   
99             date[$i]=`echo $variable | tr -s " " | cut -d" " -s -f8`
100             subtime[$i]=`echo $variable | tr -s " " | cut -d" " -s -f9`   
101             ((i = i + 1))
102          done
103          rm .watchdog_report.x
104
105#         check for terminated jobs and status changes
106          k=0
107          cat .watchdog_status.x|while read variable
108          do
109#            analyze output
110             old_comid[$k]=`echo $variable | tr -s " " | cut -d" " -s -f1`
111             old_status[$k]=`echo $variable | tr -s " " | cut -d" " -s -f2` 
112             ((k = k + 1))
113          done
114          rm .watchdog_status.x
115
116          info=""
117          for ((m=0;m<$k;m++))
118          do
119             found=0
120             for ((n=0;n<$i;n++))
121             do       
122                if [[ ${old_comid[$m]} == ${comid[$n]} ]]
123                then
124                   if [[ ${old_status[$m]} != ${status[$n]} ]]
125                   then
126                       info="$info ${old_comid[$m]} has changed status from ${old_status[$m]} to ${status[$n]}.\n"
127                   fi
128                   found=1
129                   break
130                fi
131             done
132             if (( $found == 0 ))
133             then
134                info="$info ${old_comid[$m]} has been terminated (Status was ${old_status[$m]}).\n"
135             fi
136          done
137
138#         get estimated starting time for all idle jobs and write watchdog output in .watchdog_report.x
139          while (( $j < $i ))
140          do
141             if [[ ${status[$j]} == "Idle" ]]
142             then
143                if [[ ${complex[$j]} == "hannover" ]]
144                then
145                   eststart[$j]=`ssh $gate_h -l $1 "showstart ${comid[$j]}|grep \"based start in\""`
146                else
147                   eststart[$j]=`ssh $gate_b -l $1 "showstart ${comid[$j]}|grep \"based start in\""`
148                fi
149                eststart[$j]="Start in: "`echo ${eststart[$j]} | tr -s " " | cut -d" " -s -f6`   
150             else
151                eststart[$j]=""
152             fi
153
154#            write final output line
155             ((k = j + 1))
156             printf "%-9s%8s%3s%04i%13s%11s%2s%-s%3s%-20s\n" "Job: $k:" "${status[$j]}" " @ " "${nodes[$j]}" " nodes, time:" "${walltime[$j]}" " (" "${comid[$j]}" "). " "${eststart[$j]}" >> .watchdog_report.x
157             printf "${comid[$j]} ${status[$j]}\n" >> .watchdog_status.x
158             ((j = j + 1))
159          done
160
161#         kill all windows
162          killall kdialog
163
164          timestamp=`date`
165
166#         create window and show information
167          kdialog --textbox .watchdog_report.x 550 150 --title "HLRN watchdog  (last update: $timestamp)" &
168
169#         in case of status changes and terminated jobs, inform the user
170          if [[ $info != "" ]]
171          then
172             kdialog --msgbox "$info" --title "HLRN Job Information" &
173          fi
174
175          sleep $update_frequency
176       done
177
178    fi
Note: See TracBrowser for help on using the repository browser.