EXPECT help with full buffer(?), or other available solutions

First, to level set: I'm proficient enough with basic BASH scripting for simple things (say, 4 out of 10), but this current project really requires a higher understanding of EXPECT than I have.

I have an interactive-only control application residing locally on a database server that I would like to interact with programmatically with an EXPECT script (again, local), and "display" all settings into a file.

This script does exactly that:

#!/usr/bin/expect
# dump DBS Controls
match_max 10000
spawn dbscontrol
expect "QUIT:"
send "display\r"
sleep 1
send "quit\r"
sleep 1
expect eof
sleep 1
set dbscntl $expect_out(buffer)
set log [open "dbscontrol.general.dump" "w"]
puts $log $dbscntl

So the problem: the output from the "display" command is apparently(?) longer than expect_out(buffer), as I only get about 2/3 of what is printed to the screen (approximately 7k). In reading other posts, I'm unclear if this is actually a buffer limitation, or some timing problem - but the application, script, and settings all reside on same server (no network latency), and the application isn't secure, so no logins required (besides being on the server). Running it manually is instant, so I don't believe it's a timing issue - just to be safe, I sprinkled in some Sleep time, in case the expect buffer is slow.

I've seen some posts that recommend appending the buffer to a variable, but I've not had luck getting that to work (again, my EXPECT skills aren't that sharp).

Also ~ while I need to use EXPECT to send commands to this interactive-only program, I'm open to any solution that puts the output of the screen into a file - I can parse it into what I need from there.

For instance, I could turn on SCRIPT <filename> terminal recorder and then run:

#!/usr/bin/expect
# dump all DBS Controls
spawn dbscontrol
expect "QUIT:"
send "display\r"
send "quit\r"
expect eof

...and then EXIT the script command.

Unfortunately, I couldn't figure out how to get SCRIPT scripted (heh heh) - I could put the SCRIPT command at the beginning of the script.sh, but it would hang after starting, and never get to the EXPECT (it was expecting some interaction?). Typing this, I've never tried SPAWNing SCRIPT <filename>, then SENDing an EXIT at the end (i.e. nested EXPECTs)... Not sure if (a) you can nest EXPECT the way I'm thinking, or (b) I can even start SCRIPT that way.

Anyway - I'm not stuck on any one particular solution... anything that can capture what scrolls along the screen into a file, in a scripted fashion (I'm doing this one last step manually) will be extremely helpful.

I'm sorry I don't have an example you can run (unless you have a Teradata hot-standby node) - you'll have to trust me that the above two scripts work just fine - except something is running out of buffer/time/something, and failing to record the entire output.

Thanks!
Stephen

Give this a try:

#!/usr/bin/expect
match_max 10000
spawn dbscontrol
expect "QUIT:"
send "display\r"
send "quit\r"
set log [open "dbscontrol.general.dump" "w"]
set NewLineChar "\r"
expect {
    $NewLineChar { append dbscntl $expect_out(buffer); exp_continue}
    eof { append dbscntl $expect_out(buffer) }
}
puts $log $dbscntl

Hey Chubler_XL ~ your post worked perfectly, thanks!!

I think I follow what you did - like other posts I've read, it's appending the buffer to a variable prior to file write... unlike other posts I've read, you're doing this per \r - also, unlike other solutions I've seen, this one worked the first time :slight_smile:

Thanks again!