telnet01 revision 406881062f73eeccf22ce6104e4b6cb8b38dd2ec
1#! /usr/bin/expect -f
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   : telnet
22#
23#  PURPOSE: Tests the basic functionality of `telnet`. 
24#
25#  SETUP: The program `/usr/bin/expect' MUST be installed.
26#	  The PASSWD and RHOST variables MUST be set prior to execution. 
27#
28#  HISTORY:
29#    03/01 Robbie Williamson (robbiew@us.ibm.com)
30#      -Ported
31#
32#*********************************************************************
33# 
34# telnet perform a telnet session to each host in HOST_LIST with user 
35#    RUSER for a count of LOOPCOUNT and does an ls -l /etc/hosts to
36#    verify that the telnet was established.
37#
38#*********************************************************************
39
40set TC telnet
41set TCtmp "/tmp"
42set SLEEPTIME 3
43set TESTLOG "$TCtmp"
44
45if [info exists env(RUSER)] {
46   set RUSER $env(RUSER)
47} else {
48   set RUSER root
49} 
50
51if [info exists env(PASSWD)] {
52   set PASSWD $env(PASSWD)
53} else {
54   set PASSWD .pasroot
55   send_user "PASSWD NOT SET:Using .pasroot as the PASSWD variable for $RUSER. \n"
56} 
57
58if [info exists env(RHOST)] {
59   set RHOST $env(RHOST)
60} else {
61   send_user "Please set/export the RHOST variable. \n"
62   exit 1
63} 
64
65set timeout 90
66
67if [info exists env(LOOPCOUNT)] {
68   set LOOPCOUNT $env(LOOPCOUNT)
69} else {
70   set LOOPCOUNT 25
71}
72
73# stty echo
74send_user " Starting\n"
75
76# Do foreach host on command line
77set count 0
78while {$count < $LOOPCOUNT} {
79   set count [expr $count+1]
80   foreach HOST $RHOST { 
81      send_user "Host: $HOST\n"
82
83      # telnet to the host
84      spawn telnet $HOST
85      expect -re "login:"
86      sleep 1
87      send "$RUSER\r"
88      expect -re "Password:"
89      sleep 1
90      send "$PASSWD\r"
91
92      # Wait for shell prompt
93      expect -re "$RUSER@" 
94
95      # Run passwd command - and respond to its prompts
96      send "LC_ALL=C ls -l /etc/hosts | wc -w > $TESTLOG/$RUSER.$HOST \r" 
97      # When shell prompt comes back, logout
98
99      expect -re "$RUSER@"
100      exp_send "logout\r"
101
102      send_user "CHECKING TELNET STATUS\n"
103      set nummatch [exec rsh -n -l $RUSER $HOST "cat $TESTLOG/$RUSER.$HOST|grep -c 9"] 
104      if {$nummatch==1} {
105         send_user "$TC interactive Test Successful in LOOP $count\r"
106         exec rsh -n -l $RUSER $HOST "rm -f $TESTLOG/$RUSER.$HOST" 
107      } else {
108         send_user "$TC interactive session failed\n"
109         exit 1
110      }
111   }
112}
113
114send_user "\nTest PASSES\n\n"
115exit 0
116