#!/bin/sh # The following are the strings which preface the names of the machines # when booted into the relevant OS LINUX='clustor' WINDOWSNT='winnt' # Strings used to represent the name of the OS OS_LINUX='Linux' OS_WINDOWSNT='WindowsNT' # clients which are known to be down (eg, when removed or dead). # For eg, KNOWN_DOWN='01 05' KNOWN_DOWN='' # The file used to store the previously found config CONFFILE='/usr/local/etc/client.conf' # Returns 0 if machine down, 1 if up up() { ping -c 1 $1 | grep 100 > /dev/null } # Returns the string representing the machine's last known state. last_linux() { if [ "x$USER" = 'xroot' ] then ret=`grep "^$1 " ${CONFFILE}.old | awk '{print $2}'` else ret=`grep "^$1 " ${CONFFILE} | awk '{print $2}'` fi if [ "x$ret" = "x$OS_LINUX" ] then return 1 elif [ "x$ret" = "x$OS_WINDOWSNT" ] then return 0 else return -1 fi } print() { if [ "x$USER" = 'xroot' ] then echo $1 >> $CONFFILE fi echo $1 } if [ "x$USER" = 'x' ] then USER=`whoami` fi if [ "x$USER" = 'xroot' ] then mv ${CONFFILE} ${CONFFILE}.old touch ${CONFFILE} fi for num in 01 02 03 04 05 06 07 08 09 10 11 12 13 14 51 52 53 54 55 56 57 58 59 60 61 62 64 65 66 do echo $KNOWN_DOWN | grep "$num" > /dev/null if [ $? -eq 0 ] then print "$num Down -" else # Initialisation linux=0 winnt=0 # Now determine what the current configuration is. last_linux $num lastlinux=$? if [ $lastlinux -eq 1 ] then up "$LINUX$num" linux=$? fi if [ $linux -eq 0 ] then up "$WINDOWSNT$num" winnt=$? if [ $winnt -eq 0 ] then up "$LINUX$num" linux=$? fi fi if [ $linux -eq 0 -a $winnt -eq 1 ] then # Machine is booted into Windows NT print "$num $OS_WINDOWSNT $WINDOWSNT$num" elif [ $linux -eq 1 -a $winnt -eq 0 ] then # Machine is booted into Linux print "$num $OS_LINUX $LINUX$num" elif [ $linux -eq 0 -a $winnt -eq 0 ] then # Machine is down print "$num Down -" else # Machine is running both. print "$num $OS_LINUX $LINUX$num" print "$num $OS_WINDOWSNT $WINDOWSNT$num" fi fi done