#!/bin/sh

##########################################################################
#   Script description:
#       Conveniently run top on a cluster node
#       
#   History:
#   Date        Name        Modification
#   2013-05-01  Jason Bacon Begin
##########################################################################

usage()
{
    cat << EOM

Usage: $0 complete-node-name|compute-node-index

If the compute-<argument> is a valid compute node host name, then compute-
is automatically prepended.

Example:
    node-top 002         # same as node-top compute-002
    node-top compute-002
    node-top 256g-004
    node-top compute-256g-001
    node-top raid-01

EOM
    exit 1
}


##########################################################################
#   Main
##########################################################################

if [ $# != 1 ]; then
    usage
fi

node=$1
shift
if [ 0$(node-type compute-$node) = 0compute ]; then
    node=compute-$node
fi

if ! (awk '{ print $2 }' /etc/hosts | fgrep -x $node || \
    awk '{ print $3 }' /etc/hosts | fgrep -x $node); then
    printf "$0: $node not found in /etc/hosts.\n"
    exit 1
fi

ssh -t $node top $*
