
#!/bin/ksh
# File	: do_filers_cmd
# By	: MaartenDeBoer.nl, 081211
# Subject	: To do a command on all filers
#(0.2)	: Added $SSH, cut @ ${PGM}

PGM="`basename $0|cut -d\. -f1`"
VERSION="0.2"
TMP="/tmp/${PGM}.$$"
HOSTNAME="`hostname`"
FILERS="$HOME/etc/filers"
VERBOSE=""
CMD=""
SSH="/usr/bin/ssh -n "

USAGE()
{
  echo "Usage: ${PGM} [-h] [-V] [-x] [--help] -c <command>"
  echo "  Version: ${VERSION}"
  echo "  options:"
  echo "    -c : do <command>"
  echo "    -h : this help"
  echo "    -v : verbose"
  echo "    -V : Version"
  echo "    -x : set -x"
  echo "    --help   : this help"
}

# Check options
while [ ${#} -gt 0 ]
  do
  case ${1} in
    -h | --help) USAGE; exit 1 ;;
    -c) CMD=${2}; shift ;;
    -v) VERBOSE=1 ;;
    -V) echo "${PGM}: v${VERSION}"; exit 3 ;;
    -x)  set -x ;;
    *)  echo "Option ${1} not known."; USAGE; exit 1 ;;
  esac
    shift
done

if [ ${CMD} = "" ]; then
  echo "No command defined. Exiting ..."
  exit 2
fi

echo "Doing command: ${CMD} ..."
for FILER in `cat ${FILERS}`
do
  echo "${FILER} ..."
  ${SSH} ${FILER} ${CMD}
done

exit 0

