0

Following script is ok, but it has to be modified with condition where i need help, or advice how to approach it, on place where i have to send expect for loadbalancing, if it is enabled, Yes, then i have to provide ip address of second node, i dont know how to make condition in expect, can you please help?

#!/usr/bin/expect

set timeout 2

spawn "./config.sh"

expect "Your choice:" { send "1\r" } expect "Do you want to select network (y/n)" { send "y\r" } expect "Please enter an address for the interface" { send "$env(IP)\r" } expect "Please enter the default gateway address" { send "$env(GW_IP)\r" } expect "Is this server" { send "y\r" } expect "Address range for the private network" { send "$env(PRIV_SUBNET)\r" } expect "Do you want to enable loadbalancing" { send "n\r" } expect "Please do you confirm (y/n):" { send "y\r" } expect "Do you want to clear the current configuration (first configuration)" { send "y\r" } expect "file already exist, do you want to replace it" { send "y\r" }

interact
  • 1
    Post relevant parts of the code that you've tried, show the errors you got, and the effort you made. SO is NOT a: write code service. – Ron Aug 28 '20 at 09:55
  • Expect uses the [Tcl language](http://www.tcl.tk/). You need to learn Tcl before you can write Expect scripts. If you are more comfortable with shell syntax you can try my [sexpect (Expect for Shells)](https://github.com/clarkwang/sexpect). – sexpect - Expect for Shells Aug 28 '20 at 10:10

1 Answers1

0

If that's your actual code, then you need to put each expect command on it's own line (or separate with semicolons).

Try this:

#!/usr/bin/expect

# This is for debugging. Remove or comment when you're finished testing.
exp_internal 1

spawn "./config.sh"

set timeout 2
expect_before timeout {
    puts "Timeout! Exiting"
    exit 1
}

expect "Your choice:" {send "1\r"} 
expect "Do you want to select network (y/n)" {send "y\r"} 
expect "Please enter an address for the interface" {send "$env(IP)\r"} 
expect "Please enter the default gateway address" {send "$env(GW_IP)\r"} 
expect "Is this server" {send "y\r"} 
expect "Address range for the private network" {send "$env(PRIV_SUBNET)\r"} 
expect "Do you want to enable loadbalancing" {send "n\r"} 
expect "Please do you confirm (y/n):" {send "y\r"} 
expect "Do you want to clear the current configuration (first configuration)" {send "y\r"} 
expect "file already exist, do you want to replace it" {send "y\r"} 

interact
glenn jackman
  • 238,783
  • 38
  • 220
  • 352