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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting EXPECT help with full buffer(?), or other available solutions
# 1  
Old 05-28-2011
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:
Code:
#!/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:
Code:
#!/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
# 2  
Old 05-30-2011
Give this a try:

Code:
#!/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

# 3  
Old 05-31-2011
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 Smilie

Thanks again!
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Extracting some part of Perl's Expect Buffer

Hi, I am capturing command's output on remote host using Expect. The problem is that the command line arguments also getting print with the output in file and also need to print last two relevant columns (percentage used and its mounted point). The output of $exp->before() buffer is :df... (1 Reply)
Discussion started by: suneet17
1 Replies

2. Shell Programming and Scripting

Filtering escape character from expect buffer

I have written an application in Tcl-Expect which spawns minicom and sends and receives data via the serial port. Sometimes i see that the application receives control characters along with human readable data. A search on the internet tells me that the control characters are nothing but the VT... (0 Replies)
Discussion started by: cityprince143
0 Replies

3. Shell Programming and Scripting

Expect Script not running from cron. Full Paths used

My cron file. Copied $PATH # Minute Hour Day of Month Month Day of Week Command SHELL=/bin/ksh PATH=/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/perl/lib:/perl/lib/lib/perl5:/perl/scripts:.:/perl/lib/local:/home/popeye:/temp 0... (3 Replies)
Discussion started by: popeye
3 Replies

4. Shell Programming and Scripting

Empty buffer when is full

Hello everyone! This is the situation: I execute this command from a bash script: telnet 10.99.246.14 6001 >> output.txt The question is: How I do to execute this command and empty the buffer when is full? The script is always running. Thanks a lot! (2 Replies)
Discussion started by: bobbasystem
2 Replies

5. Shell Programming and Scripting

Need help with Expect script for Cisco IPS Sensors, Expect sleep and quoting

This Expect script provides expect with a list of IP addresses to Cisco IPS sensors and commands to configure Cisco IPS sensors. The user, password, IP addresses, prompt regex, etc. have been anonymized. In general this script will log into the sensors and send commands successfully but there are... (1 Reply)
Discussion started by: genewolfe
1 Replies

6. Shell Programming and Scripting

Expect: How to read buffer for spawn

Hi All, I have to write one expect script to login to one system. I am using set timeout -1 match_max 100000 spawn ssh root@hostname Now when I do spawn ssh to that host it send some warning message and one challenge Challenge: 111-2345 I need to read this challenge value and has... (1 Reply)
Discussion started by: Lokesh Agrawal
1 Replies

7. Shell Programming and Scripting

strange expect script behavior, or am i misunderstanding expect scripting?

Hello to all...this is my first post (so please go easy). :) I feel pretty solid at expect scripting, but I'm running into an issue that I'm not able to wrap my head around. I wrote a script that is a little advanced for logging into a remote Linux machine and changing text in a file using sed.... (2 Replies)
Discussion started by: v1k0d3n
2 Replies

8. Shell Programming and Scripting

Expect buffer size increase, please help

Hi Group, I am struggling to increase buffer size of expect, sometimes after increasing the buffer size, expect captures all my expected output, sometimes not, :-( I tried match_max 700000 set expect_out(buffer) {} Could anybody guide me for any solution. HTH,... (1 Reply)
Discussion started by: jaduks
1 Replies
Login or Register to Ask a Question