Link to home
Start Free TrialLog in
Avatar of Cherylvan
Cherylvan

asked on

How do I pass arguments to autoexpect script

I have the following autoexpect script:
set timeout -1                                                            
spawn telnet 86.216.72.205                                                
match_max 100000                                                          
expect -exact "Trying...\r                                                
Connected to 86.216.72.205.\r                                              
Escape character is '^\]'.\r                                              
Local flow control off\r                                                  
\r                                                                        
Please select a destination:\r                                            
1. Power Plant administration, need Galaxy controller password.\r          
2. Network Administration, requires network administration password.\r    
"                                                                         
send -- "1\r"                                                              
expect -exact "1\r                                                        
\r                                                                        
TECLEE CLAVE:\r                                                            
ENTER PASSWORD: "                                                         
send -- "super-user\r"                                                    
expect -exact "\r                                                          
\r                                                                        
** "                                                                       
send -- "ampeers\r"                                                        
expect -exact ".\r                                                        
** "             
send -- "bye\r"  
expect eof        

I want to be able to pass it an ip address using an argument instead of having it hard coded in.  Expect is something I am totally ignorant about.  I have a file that will determine which IP address I will pass it.  Please help!!!
Avatar of wesly_chen
wesly_chen
Flag of United States of America image

Hi,

   Here is what you are looking for:
http://oldlook-search.experts-exchange.com/questions/20476614/automate-additions-of-users-and-passwords-with-shell-script.html
---
#!/usr/local/bin/expect -f   <=== path may vary
# useage: scriptname IP

set ipaddress [lindex $argv 0]

expect "IP Address: "
send "$ipaddress\n"

expect eof
----

Wesly
ASKER CERTIFIED SOLUTION
Avatar of yuzh
yuzh

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Cherylvan
Cherylvan

ASKER

Thank you so much yuzh.  It worked like a charm.  You truly are an expert!!!

Cheryl