Hello, I have an expect script where I ssh to a remote host to determine the network configuration and get from the user the network interface card that should be used. From their response, I determine the subnet mask and save the information to a text file that is later transmitted back to my local host. This is all so that I can set up virtual IP aliasing and verify that the physical IP address of the local and remote host are on the same subnet prior to continuing with the setup. I am running the script on Linux, with expect version 5.45.
The code itelf works just fine, but I'm having some issues with how it displays on the screen. As you'll see below in the example, the default system prompt displays, as does the user input command that I'm sending to the shell from the expect script.
Is there a regular expression or something that I can write to prevent the prompt and command that I'm sending from printing to the screen? I know that it should be suppressed if I have an expect command following the
Code:
send -s "\nread n_card?'Enter the network interface card number for this server (i.e. eth0): '\r
command, but everything I have tried for strings and regular expressions to expect causes the netstat -rn output to not show up all of a sudden. I'm new to expect, so I'm not really sure why this is happening.
I would really appreciate any help/suggestions. Thanks for your time!
Part of the Script Code:
Code:
expect {
-re $prompt { ;# Send individual commands and get user input
set timeout -1
# Get partner hostname and put in vipsetup.txt file
send -s "hostname > vipsetup.txt\r"
expect -re $prompt
# Display the network routing info for the user and prompt for
# network interface card number
send -s "print \"The network routing table for the $ptner server is displayed below:\n\" ; netstat -rn \r"
expect -re "\r(.*):\r"
send -s "\nread n_card?'Enter the network interface card number for this server (i.e. eth0): '\r"
interact "\r" return ;# Wait for user input from read command
send -- "\r"
send -s "echo \$n_card >> vipsetup.txt\r"
# Obtain subnet mask information for partner based on network
# interface card number being used
send -s "msk=\$(cat /etc/sysconfig/network-scripts/ifcfg-\$n_card | grep NETMASK)\r"
send -s "msk=\$(echo \${msk#NETMASK=})\r"
send -s "echo \$msk >> vipsetup.txt\r"
}
timeout {
send_user "Connection to host $hostip timed out."
exit 6
}
eof {
send_user "Connection to host $hostip failed."
exit
}
}
Script Output:
Code:
The network routing table for the PRIMARY server is displayed below:
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
10.105.65.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
0.0.0.0 10.105.65.1 0.0.0.0 UG 0 0 0 eth0
[root@remotehost root]$
[root@remotehost root]$ ber for this server (i.e. eth0): ' <
Enter the network interface card number for this server (i.e. eth0): eth0