host01 revision b692ec91c9cca98472ac87b5b4dcaf44cd902cb8
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 : host 22# 23# PURPOSE: To test the basic functionality of the `host` command. 24# 25# SETUP: If "RHOST" is not exported, then the local hostname is used. 26# 27# HISTORY: 28# 03/01 Robbie Williamson (robbiew@us.ibm.com) 29# -Ported 30# 31# 32#----------------------------------------------------------------------- 33# Uncomment line below for debug output 34#trace_logic=${trace_logic:-"set -x"} 35$trace_logic 36 37RHOST=${RHOST:-`hostname`} 38NUMLOOPS=${NUMLOOPS:-20} 39SLEEPTIME=${SLEEPTIME:-0} 40 41#----------------------------------------------------------------------- 42# 43# FUNCTION: do_test 44# 45#----------------------------------------------------------------------- 46 47do_test() 48{ 49 $trace_logic 50 echo "$this_file: doing $0." 51 52 count=0 53 while [ $count -lt $NUMLOOPS ] 54 do 55 host $RHOST 56 if [ $? -eq 0 ]; then 57 rhost_addr=`host $RHOST | tr -s ',' ' ' | awk '{print $4}'` 58 host $rhost_addr 59 [ $? -eq 0 ] || end_testcase "host can not do a reverse lookup" 60 else 61 end_testcase "host $RHOST on local machine failed" 62 fi 63 count=$(( $count + 1 )) 64 sleep $SLEEPTIME 65 done 66} 67 68#============================================================================= 69# FUNCTION NAME: end_testcase 70# 71# FUNCTION DESCRIPTION: Clean up 72# 73# PARAMETERS: string, IF AND ONLY IF the testcase fails 74# 75# RETURNS: None. 76#============================================================================= 77 78end_testcase() 79{ 80 $trace_logic 81 echo "$this_file: doing $0." 82 83 [ $# -eq 0 ] && { echo "Test Successful"; exit 0; } 84 echo "Test Failed: $@" 85 exit 1 86} 87 88#----------------------------------------------------------------------- 89# FUNCTION: MAIN 90#----------------------------------------------------------------------- 91do_test 92end_testcase 93