[ale] expect scripting question

Jerry Z. Yu z.yu at ptek.com
Thu Apr 11 17:04:53 EDT 2002


	If perl is your main language, you'd try out the Expect module 
first, instead of using two seperate language...

To answer your questions directly,	

	Of course, there is an 'exit' , you can use 'exit statusCode' such 
as 'exit -1' or 'exit 0'
	
	Expect's loop/conditional thing are basically TCL shell syntax. 
'explore expect' the Oriley book is good. 
 
	# example, check # of argument
	if $argc<1 {
		send_user "\tUsage: $argv0 hostname/IP\r\n"; 
		send_user "Exiting: Insufficient argument\r\n"
		 exit -1
	}

	# expect cmd itself is like a switch  or case statement
	# For example, this is the beginning of what I wrote for FTP
	spawn ftp $host
	set timeout 400
expect {
        timeout {puts "my time is out $timeout"; exit}
        "nnection timed out" {puts "ftp client timed out. going to retry"; 
send "open $host\r";exp_continue}
        "onnection refused" {puts "Error: Connection refused";exit}
        "nknown host" {puts "Error: host Name '$host' can't be resolved"; 
exit}
        "ftp> " {exp_continue}
        "User ($host:(none)): "
}
send "$uid\r"


	


On 11 Apr 2002, Gene Matthews wrote:

#I'm trying to write an expect script to test a remote console server.
#
#I have the following script:
#
#
##!/usr/bin/expect -f
#
#spawn telnet $argv
#expect "login:"
#send "voicetek\r"
#expect "Password: "
#send "itsasecret\r"
#expect ":ccs"
#send "show\r"
#expect "rcm:ccs"
#send "exit\r"
#
#
#This script works fine standalone (e.g. ./rcmcheck servername). 
#However, what I would like to do is call it from perl script and be able
#to test it's success.  
#
#My perl script first tries to ping the box, and if the box is reachable
#I want to call this expect script and be able to determine if the telnet
#was successful.  I want to be able to determine if the telnet connection
#is 1) refused, 2) times out, or 3) successful.
#
#My expect skills are very new (i.e. weak).  Does expect have an 'exit'
#statement similar to perl (and shells) and some conditional structures? 
#Can anyone give me some advice/pointers or point me to any good online
#resources for learning expect?
#
#Thanks.
#
#Gene Matthews
#Matthews Midrange Consulting, Inc.
#(678) 923-8327
#(877) 882-6291 (toll free)
#http://mmc-inc.com
#
#
#---
#This message has been sent through the ALE general discussion list.
#See http://www.ale.org/mailing-lists.shtml for more info. Problems should be 
#sent to listmaster at ale dot org.
#

Jerry Z. Yu					+1-404-262-8544 (O)
systems engineer				z.yu at voicecom.com
is support, voicecom, llc			www.voicecom.com



---
This message has been sent through the ALE general discussion list.
See http://www.ale.org/mailing-lists.shtml for more info. Problems should be 
sent to listmaster at ale dot org.






More information about the Ale mailing list