Expect_out(buffer) works but it doesn't get all lines

Hello "expect" experts

I am new at Expect. I have searched for a little while how to capture multiple lines with Expect and I am almost succeeded on that but I don't get all the lines of a command's output that the script executes on a server.

Here is how my script works in a nutshell -

The program establishes a ssh session into an Unix server and from there it runs another ssh into another server where a command is excuted on the final target server (after authentication is satisfied). The command produces an output with multiple lines (more than 30). My program only gets the last 10 or so lines of the output.

... Here are the important lines of the code that concerns me.

(1) expect -re "${promptvio}\$"
(2) send ${command2}\r
(3) expect -re "${promptvio}\$"
(4) puts "'$expect_out(buffer)'."
(5) send "exit\r"
(6) expect "login:"
(7) send "\~\.\r

In line (1), it expects a "$" prompt
In line (2), it sends a command to the server, which produces an output with multiple lines
In line (3), it expects again the "$" prompt
In line (4), it prints the contain of $expect_out(buffer) and this is the instruction that doesn't capture all the lines of the command.:confused:

Any help, would be appreciated.

Thanks

I ften used autoexpect to write my expect scripts, as I am not a tk/tkl guy yet. Why not collect your lines from the log file or run it under script? Apparently this is an often misused facility: "expect_out(buffer) has the content of the previous send"

I am not sure what you mean.

I think my problem relies on the construction of the regular expresion for the "expect" command. My command's output has many lines (including new lines) and it doesn't follow a pattern

That article suggests you may need an expanded buffer, and that it is usually the wrong way to achieve that end.

This is my command's output. It doesn't look like this all the times as the command varies .. Please help me to build the reg expression for the expect command

expect -re "\\\$ " # doesn't capture all lines

 
$ lname             status      description
L2cache0         Available   L2 Cache
en0              Defined     Standard Ethernet Network Interface
en1              Defined     Standard Ethernet Network Interface
en2              Defined     Standard Ethernet Network Interface
en3              Defined     Standard Ethernet Network Interface
en4              Defined     Standard Ethernet Network Interface
en5              Defined     Standard Ethernet Network Interface
en6              Available   Standard Ethernet Network Interface

---------- Post updated at 04:43 PM ---------- Previous update was at 04:36 PM ----------

Thanks DGPicked for your help, but how can I capture the output the log file?

Just pipe the expect output to a file '>log 2>&1' or a pipe '2>&1 | postprocess' and post-process it. As I recall, everything flows out some std*. Postprocess could be sed or shell or whatever you are comfortable with.

However, your efforts may work if you bump the buffer size match_max and use this to remove the prompt How to access the result of a remote command in Expect

DGPicked , you hit the nail on the head.

The buffer size was the issue. I expanded it and I was able to read all lines from the command's output. I also had an issue with the defintion of the prompt . So, your reference was really useful.

Thank you so much !