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 program; if not, write to the Free Software 17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 # 19 # 20 # 21 # FILE : rsh 22 # 23 # PURPOSE: To test the basic functionality of the `rsh` command. 24 # 25 # SETUP: The home directory of root on the machine exported as "RHOST" 26 # MUST have a ".rhosts" file with the hostname of the machine 27 # where the test is executed. 28 # 29 # HISTORY: 30 # 03/01 Robbie Williamson (robbiew (at] us.ibm.com) 31 # -Ported 32 # 33 # 34 # 35 #---------------------------------------------------------------------- 36 37 do_setup() 38 { 39 40 FAIL_IMMEDIATELY=${FAIL_IMMEDIATELY:-1} 41 SLEEPTIME=${SLEEPTIME:-0} 42 NUMLOOPS=${NUMLOOPS:-1} 43 44 export TST_TOTAL=$NUMLOOPS 45 46 tst_setup 47 48 exists awk hostname rsh 49 50 RHOST=${RHOST:-`hostname`} 51 52 } 53 54 #----------------------------------------------------------------------- 55 # 56 # FUNCTION: do_test 57 # 58 #----------------------------------------------------------------------- 59 60 do_test() 61 { 62 63 while [ $TST_COUNT -le $NUMLOOPS ]; do 64 65 PASSED=0 66 67 if OUT=$(rsh -n -l root $RHOST 'ls -l /etc/hosts'); then 68 69 # 70 # Successful output would be something of the form: 71 # 72 # gcooper@orangebox ~ $ ls -l /etc/hosts 73 # -rw-r--r-- 1 root root 463 Jul 5 09:26 /etc/hosts 74 # 75 echo "$OUT" | 76 awk 'BEGIN { RET=1 } NF == 9 && $NF == "/etc/hosts" { RET=0 } END { exit RET }' \ 77 > /dev/null 2>&1 78 79 if [ $? -eq 0 ] ; then 80 tst_resm TPASS "rsh to $RHOST test succeeded" 81 PASSED=1 82 fi 83 84 fi 85 86 if [ $PASSED -ne 1 ] ; then 87 tst_resm TFAIL "rsh to $RHOST failed" 88 # If the first rsh failed, the likelihood that the rest will 89 # succeed is low. 90 if [ "$FAIL_IMMEDIATELY" = "1" ] && [ $TST_COUNT -eq 1 ]; then 91 exit 2 92 fi 93 fi 94 95 sleep $SLEEPTIME 96 incr_tst_count 97 98 done 99 100 } 101 102 #---------------------------------------------------------------------- 103 # FUNCTION: MAIN 104 # PURPOSE: To invoke the functions to perform the tasks described in 105 # the prologue. 106 # INPUT: None. 107 # OUTPUT: A testcase run log with the results of the execution of this 108 # test. 109 #---------------------------------------------------------------------- 110 . net_cmdlib.sh 111 112 read_opts $* 113 do_setup 114 do_test 115 end_testcase 116