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!!!
System Programming

Avatar of undefined
Last Comment
Cherylvan

8/22/2022 - Mon
wesly_chen

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
yuzh

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Cherylvan

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

Cheryl
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck