1#!/bin/sh
2#
3#
4#   Copyright (c) International Business Machines  Corp., 2000
5#
6#   This program is free software;  you can redistribute it and/or modify
7#   it under the terms of the GNU General Public License as published by
8#   the Free Software Foundation; either version 2 of the License, or
9#   (at your option) any later version.
10#
11#   This program is distributed in the hope that it will be useful,
12#   but WITHOUT ANY WARRANTY;  without even the implied warranty of
13#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
14#   the GNU General Public License for more details.
15#
16#   You should have received a copy of the GNU General Public License
17#   along with this program;  if not, write to the Free Software
18#   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19#
20#
21#
22#  FILE             : rup
23#
24#  TEST DESCRIPTION : Basic test for the `rup` command.
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.
29#
30#  HISTORY:
31#    04/18/01 Robbie Williamson (robbiew@us.ibm.com)
32#      -Written
33#
34# CMD      FLAG      ARGS
35# rup
36# rup                rem_host
37# rup	    -d
38# rup       -h
39# rup       -t
40# rup       -l
41# rup                bogus_host
42# rup      -bogus_flag
43#***********************************************************************
44#Uncomment line below for debug output.
45#trace_logic=${trace_logic:-"set -x"}
46
47$trace_logic
48this_file=${0##*/}
49TC=rup01
50TCtmp=${TCtmp:=`pwd`}
51TCbin=${TCbin:=`pwd`}
52TCsrc=${TCsrc:=$TCbin}
53LUSER=${LUSER:=root}
54RHOST=${RHOST:=`hostname`}
55CLEANUP=${CLEANUP:="ON"}
56PID=0
57export TCID=$TC
58export TST_TOTAL=1
59export TST_COUNT=1
60
61#=============================================================================
62# FUNCTION NAME:        do_test
63#
64# FUNCTION DESCRIPTION: Perform the test
65#
66# PARAMETERS:           None.
67#
68# RETURNS:              None.
69#=============================================================================
70do_test()
71{
72$trace_logic
73
74echo "Checking for rstatd on $RHOST"
75
76rpcinfo -u $RHOST rstatd 3 > /dev/null 2>&1
77if [ $? -ne 0 ]; then
78  echo "Attempting to start rstatd on $RHOST"
79  rsh -n -l root $RHOST "/usr/sbin/rpc.rstatd &"
80  [ $? -eq 0 ] || end_testcase "rstatd is inactive on $RHOST"
81  PID=`rsh -n $RHOST ps -ewf | grep rstatd | awk '{print $2 }'`
82  echo "rstatd started on $RHOST"
83fi
84
85echo "Test rup with defaults....please be patient"
86# rusers with no options broadcasts over the net and reports
87# responses as it receives them. Time-out for responses is approx. 2 minutes.
88
89echo "rup"
90rup
91[ $? -eq 0 ] || end_testcase "rup with defaults - failed"
92
93echo "Test rusers with options set...please be patient"
94# Go through matrix of rup options:
95
96echo "rup $RHOST"
97rup $RHOST | grep $RHOST
98[ $? -eq 0 ] || end_testcase "rup $RHOST - failed"
99
100echo "rup -d"
101rup -d
102[ $? -eq 0 ] || end_testcase "rup -d - failed"
103
104echo "rup -h"
105rup -h
106[ $? -eq 0 ] || end_testcase "rup -h - failed"
107
108echo "rup -l"
109rup -l
110[ $? -eq 0 ] || end_testcase "rup -l - failed"
111
112echo "rup -t"
113rup -t
114[ $? -eq 0 ] || end_testcase "rup -t - failed"
115
116echo "Test rusers with bad options"
117echo "rup <invalid hostname>"
118rup bogushost > /dev/null 2>&1
119[ $? -ne 0 ] || end_testcase "rup <invalid hostname> should fail"
120
121echo "rup -<invalid flag>"
122rup -bogusflag > /dev/null 2>&1
123[ $? -eq 1 ] || end_testcase "rup -<invalid flag> should fail"
124}
125
126#=============================================================================
127# FUNCTION NAME:        do_cleanup
128#
129# FUNCTION DESCRIPTION: Clean up
130#
131# PARAMETERS:           None.
132#
133# RETURNS:              None.
134#=============================================================================
135do_cleanup()
136{
137    $trace_logic
138
139    if [ "$PID" != 0 ]; then
140        # Kill rup on remote machine
141        rsh -n $RHOST kill -15 $PID
142        echo "rstatd daemon stopped on $RHOST"
143    fi
144}
145
146#=============================================================================
147# FUNCTION NAME:        end_testcase
148#
149# FUNCTION DESCRIPTION: Clean up
150#
151# PARAMETERS:           string, IF AND ONLY IF the testcase fails
152#
153# RETURNS:              None.
154#=============================================================================
155
156end_testcase()
157{
158   $trace_logic
159   echo "$this_file: doing $0."
160   if [ "$CLEANUP" = "ON" ]; then
161     do_cleanup
162   fi
163
164   [ $# = 0 ] && { tst_resm TPASS "Test Successful"; exit 0; }
165   tst_resm TFAIL "Test Failed: $@"
166   exit 1
167}
168
169#=============================================================================
170# MAIN PROCEDURE
171#=============================================================================
172
173do_test
174end_testcase
175