#!/bin/sh

# List dead nodes (sgeexecd not responding).

# Dave Love <fx@gnu.org>, 2008-09
# Copyright (C) 2008 The University of Liverpool
# Licence: FreeBSD <http://www.gnu.org/licenses/license-list.html#FreeBSD>

usage () {
    echo "Usage: $(basename $0) [-w]
List dead nodes (where the SGE exec daemon isn't responding).
-w means separate node names with commas, to produce a list suitable
for the -w arg of pdsh."
}

case $1 in
    --help) usage; exit;;
    -w) comma=1;;
    '') : ;;
    *) usage 1>&2; exit 1;;
esac

out=$(qhost |
      grep ' - ' |		# dead
      grep -v global |		# ignore global
      cut -d ' ' -f 1)
if [ -z "$comma" ]; then
    echo "$out"
else
  echo "$out" | tr "\n" , | sed -e 's/,$//'
fi

