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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Expect_out(buffer) works but it doesn't get all lines
# 1  
Old 02-15-2013
Error 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.Smilie

Any help, would be appreciated.

Thanks
# 2  
Old 02-15-2013
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"
# 3  
Old 02-15-2013
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
# 4  
Old 02-15-2013
That article suggests you may need an expanded buffer, and that it is usually the wrong way to achieve that end.
# 5  
Old 02-15-2013
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?
# 6  
Old 02-15-2013
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
# 7  
Old 02-16-2013
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 !
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SSh works but sftp doesn't for all users except root

I am sorry if i post in wrong Form. i have AIX server in which ssh works for all users but sftp only works for root user . it is too much important for me to solve this . Your help will be greatly appreciated. (1 Reply)
Discussion started by: khalid khanAIB
1 Replies

2. Shell Programming and Scripting

Trying to parse expect_out(buffer)

trying to telnet to a device, list the files, and delete them. I can get the script to telnet and log in OK, and even issue the command to list out the files. I can't figure out how to parse the expect_out(buffer) and extract the file name for use in the delete command. the files list out like... (4 Replies)
Discussion started by: imatinkerer
4 Replies

3. Shell Programming and Scripting

Jumbled output in expect_out(buffer)

I have a code like this : set ipv6_acl_max_chars test_acl_max_chars123456a789%s%d2345678ww134rt789qa23456789012345%c89012%a56789012x4r67890test_acl_max_chars1234567890.01234aabcdob34567aBC0 spawn telnet $myip expect "Login:" { send "admin\r" } expect "Password:" {send "admin\r" }... (0 Replies)
Discussion started by: ylucki
0 Replies

4. Programming

Flushing expect_out(buffer)

Can some one tell me how to flush expect_out(buffer)? below is my code expect -re {.*} {} expect "swpackages>*" send -i $con "trial.bat \r" set outcome $expect_out(buffer) expect "*continue*" set prevreport $expect_out(buffer) send "\r \r"; problem is :- I am getting "pre" stuffs... (0 Replies)
Discussion started by: cityprince143
0 Replies

5. Programming

[SOLVED] Flushing expect_out(buffer) inside a loop

Greetings, Having an issue with the expect_out(buffer). in a foreach loop through some switches I am grabbing some arp table information and writing it out to output files (1 each for each switch looped through). The first iteration works fine. the second iteration of the loop writes the... (0 Replies)
Discussion started by: SuperSix4
0 Replies

6. Red Hat

Samba 3.0.33 (sorta) works, 3.5.4 doesn't

I'm trying to get a RHEL 5.4 base system to authenticate against a W2K8 domain With the stock samba-3.0.33, I can use wbinfo and getent just fine, but I cannot actually authenticate. Googling finally led to a bug that strongly suggests that 3.0.33 cannot and will never be able to ... (1 Reply)
Discussion started by: jnojr
1 Replies

7. Shell Programming and Scripting

Script works but doesn't?

Hi everyone I'm new here so and I'm just starting to learn a bit of Solaris and I'm working on repairing 10 year old scripts for our system here at work. When I execute the commands at my prompt everything go's through smooth. I'm using gedit to edit my code because I'm still getting used to the... (4 Replies)
Discussion started by: 82280zx
4 Replies

8. Shell Programming and Scripting

expect_out buffer no such variable running script background

I am trying to use send and receive using expect. the expect_out(buffer) is working fine while it is running it as foreground. But the same script when it is ran as background, the expect_out(buffer) errored out. Is there any factor influence when we run script in foreground and in background? ... (0 Replies)
Discussion started by: shellscripter
0 Replies

9. Shell Programming and Scripting

Script works but doesn't with cron

Good morning, The script below without the hilited text successfully FTPs the files in question to the other server when it is called from the crontab. I don't want to establish an FTP connection when there are no files so I tried including the hilited lines to only establish an FTP connection... (6 Replies)
Discussion started by: philplasma
6 Replies

10. Shell Programming and Scripting

expect_out(buffer) empty

I have only some info into my buffer, but after a rssi command I see the folowing lines expected into buffer but not present : rssi=-106 rssi=-109 I see in my buffer only the first part of the output, here you are a part of script : #!/usr/bin/expect -f #global expect_out match_max 10000000... (1 Reply)
Discussion started by: ugobale
1 Replies
Login or Register to Ask a Question