| #!/bin/sh |
| # |
| # Copyright (c) International Business Machines Corp., 2000 |
| # |
| # This program is free software; you can redistribute it and/or modify |
| # it under the terms of the GNU General Public License as published by |
| # the Free Software Foundation; either version 2 of the License, or |
| # (at your option) any later version. |
| # |
| # This program is distributed in the hope that it will be useful, |
| # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| # the GNU General Public License for more details. |
| # |
| # You should have received a copy of the GNU General Public License |
| # along with this program; if not, write to the Free Software |
| # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| # |
| # |
| # |
| # FILE : rwho |
| # |
| # PURPOSE: To test the basic functionality of the rwhod daemon using the |
| # `rwho` and `ruptime` commands. |
| # |
| # SETUP: The home directory of root on the machine exported as "RHOST" |
| # MUST have a ".rhosts" file with the hostname of the machine |
| # where the test is executed. Also, both machines MUST have |
| # the rwhod daemon installed. However, it does not need to be |
| # active, the test will handle this. |
| # |
| # HISTORY: |
| # 06/09 Manoj Iyer manjo@mail.utexas.edu |
| # - Modified to use test harness API and also fix defects |
| # 03/01 Robbie Williamson (robbiew@us.ibm.com) |
| # -Ported |
| # |
| # |
| #============================================================================== |
| # error codes: 0 rwho/ruptime successful |
| # 1 rwho failed no local and remote host in file |
| # 2 ruptime failed no local and remote host in file |
| #============================================================================== |
| |
| #----------------------------------------------------------------------- |
| # |
| # FUNCTION: do_setup |
| # |
| #----------------------------------------------------------------------- |
| |
| do_setup() |
| { |
| |
| TCtmp=${TCtmp:-$LTPROOT/testcases/bin/$TC${EXEC_SUFFIX}$$} |
| |
| PID=0 |
| RHOST_PID=0 |
| SLEEPTIME=${SLEEPTIME:-20} |
| NUMLOOPS=${NUMLOOPS:-25} |
| OUTFILE=${OUTFILE:-$TCtmp/${TC}.out} |
| |
| tst_setup |
| |
| exists awk cut hostname killall ps rsh rwho |
| |
| LHOST=`hostname | cut -f1 -d.` |
| RHOST=${RHOST:-$LHOST} |
| |
| trap do_cleanup EXIT |
| |
| if ! ps -ef | awk '/rwhod/ && $0 !~ /awk/'; then |
| tst_resm TINFO "Starting rwhod on $LHOST" |
| rwhod || end_testcase "Unable to start rwhod on $LHOST" |
| PID=1 |
| sleep $SLEEPTIME |
| fi |
| |
| if ! rsh -n -l root $RHOST ps -ef | awk '/rwhod/ && $0 !~ /awk/'; then |
| tst_resm TINFO "Starting rwhod on $RHOST" |
| if ! rsh -n -l root $RHOST /usr/sbin/rwhod; then |
| end_testcase "Unable to start rwhod on $RHOST" |
| fi |
| RHOST_PID=$(rsh -n -l root $RHOST ps -ef | awk '/rwhod/ && $0 !~ /awk/ {print $2 ; exit}') |
| if [ -z "$RHOST_PID" ]; then |
| RHOST_PID=0 |
| end_testcase "Unable to start rwhod on $RHOST" |
| fi |
| sleep $SLEEPTIME |
| fi |
| |
| RHOSTNAME=`rsh -n -l root $RHOST hostname | cut -f1 -d.` |
| if [ -z "$RHOSTNAME" ]; then |
| end_testcase "Unable to determine RHOSTNAME" |
| fi |
| |
| } |
| |
| #----------------------------------------------------------------------- |
| # |
| # FUNCTION: do_test |
| # |
| #----------------------------------------------------------------------- |
| |
| do_test() |
| { |
| |
| while [ $TST_COUNT -le $NUMLOOPS ]; do |
| rwho -a > $OUTFILE |
| HOST=`awk "\\$2 ~ /$LHOST>/" $OUTFILE | cut -f1 -d: | sort -u` |
| [ "$HOST" = "$LHOST" ] || end_testcase "$LHOST is not in rwho outfile" |
| HOST=`awk "\\$2 ~ /$RHOSTNAME>/" $OUTFILE | cut -f1 -d: | sort -u` |
| [ "$HOST" = "$RHOSTNAME" ] || end_testcase "$RHOSTNAME is not in rwho outfile" |
| |
| ruptime -a > $OUTFILE |
| HOST=`awk "\\$1 ~ /$LHOST>/" $OUTFILE | sort -u` |
| [ "$HOST" = "$LHOST" ] || end_testcase "$LHOST is not in ruptime outfile" |
| HOST=`awk "\\$1 ~ /$RHOSTNAME>/" $OUTFILE | sort -u` |
| [ "$HOST" = "$RHOSTNAME" ] || end_testcase "$RHOSTNAME is not in ruptime outfile" |
| |
| tst_resm TINFO "Test $COUNT of $NUMLOOPS complete" |
| incr_tst_count |
| done |
| } |
| |
| #----------------------------------------------------------------------- |
| # |
| # FUNCTION: do_cleanup |
| # |
| #----------------------------------------------------------------------- |
| |
| do_cleanup() |
| { |
| if [ $PID -ne 0 ]; then |
| tst_resm TINFO "Stopping rwhod on $LHOST" |
| killall rwhod |
| fi |
| |
| if [ $RHOST_PID -ne 0 ]; then |
| tst_resm TINFO "Stopping rwhod on $RHOST" |
| rsh -n -l root $RHOST "killall rwhod" |
| fi |
| |
| tst_cleanup |
| |
| } |
| |
| #----------------------------------------------------------------------- |
| # |
| # FUNCTION: MAIN |
| # |
| #----------------------------------------------------------------------- |
| . net_cmdlib.sh |
| |
| read_opts $* |
| do_setup |
| do_test |
| end_testcase |