rwho01 revision a2df21db677c52a5eb8d9b9ecff7316701c076c1
1#!/bin/sh 2# 3# Copyright (c) International Business Machines Corp., 2000 4# 5# This program is free software; you can redistribute it and/or modify 6# it under the terms of the GNU General Public License as published by 7# the Free Software Foundation; either version 2 of the License, or 8# (at your option) any later version. 9# 10# This program is distributed in the hope that it will be useful, 11# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13# the GNU General Public License for more details. 14# 15# You should have received a copy of the GNU General Public License 16# along with this pronram; if not, write to the Free Software 17# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18# 19# 20# 21# FILE : rwho 22# 23# PURPOSE: To test the basic functionality of the rwhod daemon using the 24# `rwho` and `ruptime` commands. 25# 26# SETUP: The home directory of root on the machine exported as "RHOST" 27# MUST have a ".rhosts" file with the hostname of the machine 28# where the test is executed. Also, both machines MUST have 29# the rwhod daemon installed. However, it does not need to be 30# active, the test will handle this. 31# 32# HISTORY: 33# 03/01 Robbie Williamson (robbiew@us.ibm.com) 34# -Ported 35# 36# 37#============================================================================== 38# error codes: 0 rwho/ruptime successful 39# 1 rwho failed no local and remote host in file 40# 2 ruptime failed no local and remote host in file 41#============================================================================== 42#Uncomment line below for debug output. 43#trace_logic=${trace_logic:-"set -x"} 44$trace_logic 45 46LHOST=`hostname | cut -f1 -d.` 47RHOST=${RHOST:-$LHOST} 48TC=rwho 49TCtmp=${TCtmp:-/tmp/$TC} 50CLEANUP=${CLEANUP:-ON} 51 52PID=0 53RHOST_PID=0 54SLEEPTIME=${SLEEPTIME:-20} 55NUMLOOPS=${NUMLOOPS:-25} 56OUTFILE=${OUTFILE:-$TCtmp/rwho.out} 57 58#----------------------------------------------------------------------- 59# 60# FUNCTION: do_setup 61# 62#----------------------------------------------------------------------- 63 64do_setup() 65{ 66 $trace_logic 67 ps -ef | grep rwhod | grep -v grep 68 if [ $? != 0 ]; then 69 echo "Starting rwhod on $LHOST" 70 /usr/sbin/rwhod 71 [ $? = 0 ] || end_testcase "Unable to start rwhod on $LHOST" 72 PID=1 73 sleep $SLEEPTIME 74 fi 75 76 rsh -n -l root $RHOST ps -ef | grep rwhod 77 if [ $? != 0 ]; then 78 echo "Starting rwhod on $RHOST" 79 rsh -n -l root $RHOST /usr/sbin/rwhod 80 if [ $? != 0 ]; then 81 end_testcase "Unable to start rwhod on $RHOST" 82 fi 83 RHOST_PID=1 84 sleep $SLEEPTIME 85 fi 86 87 RHOSTNAME=`rsh -n -l root $RHOST hostname`| cut -f1 -d. 88 89 mkdir -p $TCtmp 90} 91 92#----------------------------------------------------------------------- 93# 94# FUNCTION: do_test 95# 96#----------------------------------------------------------------------- 97 98do_test() 99{ 100 $trace_logic 101 102 COUNT=1 103 while [[ $COUNT -le $NUMLOOPS ]] 104 do 105 rwho -a > $OUTFILE 106 HOST=`awk '{print $2}' $OUTFILE|grep $LHOST|cut -f1 -d:|sort -u` 107 [[ $HOST = $LHOST ]] || end_testcase "$LHOST is not in rwho outfile" 108 HOST=`awk '{print $2}' $OUTFILE|grep $RHOSTNAME|cut -f1 -d:|sort -u` 109 [[ $HOST = $RHOSTNAME ]] || end_testcase "$RHOSTNAME is not in rwho outfile" 110 111 ruptime -a > $OUTFILE 112 HOST=`awk '{print $1}' $OUTFILE|grep $LHOST|sort -u` 113 [[ $HOST = $LHOST ]] || end_testcase "$LHOST is not in ruptime outfile" 114 HOST=`awk '{print $1}' $OUTFILE|grep $RHOSTNAME|sort -u` 115 [[ $HOST = $RHOSTNAME ]] || end_testcase "$RHOSTNAME is not in ruptime outfile" 116 117 echo "Test $COUNT of $NUMLOOPS complete" 118 (( COUNT = COUNT + 1 )) 119 done 120} 121 122#----------------------------------------------------------------------- 123# 124# FUNCTION: do_cleanup 125# 126#----------------------------------------------------------------------- 127 128do_cleanup() 129{ 130 rm -fr $TCtmp 131 if [ $PID != 0 ]; then 132 echo "Stopping rwhod on $LHOST" 133 killall rwhod 134 fi 135 136 if [ $RHOST_PID != 0 ]; then 137 echo "Stopping rwhod on $RHOST" 138 rsh -n -l root $RHOST "killall rwhod" 139 fi 140} 141 142#============================================================================= 143# FUNCTION NAME: end_testcase 144# 145# FUNCTION DESCRIPTION: Clean up 146# 147# PARAMETERS: string, IF AND ONLY IF the testcase fails 148# 149# RETURNS: None. 150#============================================================================= 151 152end_testcase() 153{ 154 $trace_logic 155 156 if [[ $CLEANUP -eq "ON" ]]; then 157 do_cleanup 158 fi 159 [[ $# -eq 0 ]] && { echo "Test Successful"; exit 0; } 160 echo "Test Failed: $@" 161 exit 1 162} 163 164#----------------------------------------------------------------------- 165# 166# FUNCTION: MAIN 167# 168#----------------------------------------------------------------------- 169do_setup 170do_test 171end_testcase 172