#!/bin/bash
# file   : reboot_client
# author : Jacek Radajewski
# date   : 3 June 1997
#
# script to reboot a client specified on command line
# this script must be executed from alpha

#-------------------------------------------------------------------
# first check if started from alpha
#-------------------------------------------------------------------

if [ $(/bin/uname -n) != "alpha.beowulf.usq.edu.au" ] ; then
    echo "$0 : I must be started from alpha.beowulf.usq.edu.au"
    echo "$0 : I was started from $(/bin/uname -n)"
    exit 1
fi

#-------------------------------------------------------------------
# check if the host specified is a valid one
#-------------------------------------------------------------------

/bin/grep "$1" /usr/local/admin/hosts | grep -v "grep"  1> /dev/null 2>&1

if [ $? != 0 ] ; then
    echo "$0 : $1 is not one of my clients"
    echo "$0 : Giving up."
    exit 1
fi

#-------------------------------------------------------------------
# unmount /host from all clients
#-------------------------------------------------------------------

for host in $(cat /usr/local/admin/hosts) ; do
    echo -n "Unmounting /$1 on $host ... "
    rsh $host "/bin/umount -v /$1 &"
done;

#-------------------------------------------------------------------
# reboot the client
#-------------------------------------------------------------------

echo -n "Sending reboot command to $1 ... "
/usr/bin/rsh $1 "/sbin/shutdown -r now" && echo " done. "



