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