Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 05-28-2015, 04:37 PM   #1
LQ Newbie
Registered: Apr 2015
Location: AZ
Posts: 14

Rep: Reputation: Disabled
Regular expression in expect script to prevent printing to screen

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

Script Output:
The network routing table for the PRIMARY server is displayed below:
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface   U         0 0          0 eth0         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

Last edited by legendmac; 05-28-2015 at 04:44 PM.


expect, linux, ssh

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] bash script using regular expression edwardcode Programming 5 05-31-2012 02:07 AM
Bash Script / Regular Expression Problem rm_-rf_windows Linux - General 4 03-28-2012 01:05 PM
tcl expect - problem with regular expression in interact mode chekhov_neo Programming 3 12-09-2010 02:55 PM
Using regular expression in expect script nik1984 Programming 1 08-28-2008 06:25 AM
printing the numbers between 20 to 80 in perl using a regular expression iceman_san Linux - Newbie 3 08-27-2007 01:35 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:27 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration