[ale] expect scripting question

Gene Matthews gene at mmc-inc.com
Thu Apr 11 17:17:05 EDT 2002


On Thu, 2002-04-11 at 17:04, Jerry Z. Yu wrote:
> 	If perl is your main language, you'd try out the Expect module 
> first, instead of using two seperate language...

Jerry,

I like that idea.  I'll go check out CPAN and see what I can find for
doc and examples.


> 
> 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"
> 
> 

Thanks for the examples.


gene

-- 
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.






More information about the Ale mailing list