Sponsored Content
Top Forums Shell Programming and Scripting EXPECT help with full buffer(?), or other available solutions Post 302525804 by toeharp on Saturday 28th of May 2011 02:37:42 PM
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
 

8 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

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

8. 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
CHECKBASHISMS(1)					      General Commands Manual						  CHECKBASHISMS(1)

NAME
checkbashisms - check for bashisms in /bin/sh scripts SYNOPSIS
checkbashisms script ... checkbashisms --help|--version DESCRIPTION
checkbashisms, based on one of the checks from the lintian system, performs basic checks on /bin/sh shell scripts for the possible presence of bashisms. It takes the names of the shell scripts on the command line, and outputs warnings if possible bashisms are detected. Note that the definition of a bashism in this context roughly equates to "a shell feature that is not required to be supported by POSIX"; this means that some issues flagged may be permitted under optional sections of POSIX, such as XSI or User Portability. In cases where POSIX and Debian Policy disagree, checkbashisms by default allows extensions permitted by Policy but may also provide options for stricter checking. OPTIONS
--help, -h Show a summary of options. --newline, -n Check for "echo -n" usage (non POSIX but required by Debian Policy 10.4.) --posix, -p Check for issues which are non POSIX but required to be supported by Debian Policy 10.4 (implies -n). --force, -f Force each script to be checked, even if it would normally not be (for instance, it has a bash or non POSIX shell shebang or appears to be a shell wrapper). --extra, -x Highlight lines which, whilst they do not contain bashisms, may be useful in determining whether a particular issue is a false posi- tive which may be ignored. For example, the use of "$BASH_ENV" may be preceded by checking whether "$BASH" is set. --version, -v Show version and copyright information. EXIT VALUES
The exit value will be 0 if no possible bashisms or other problems were detected. Otherwise it will be the sum of the following error val- ues: 1 A possible bashism was detected. 2 A file was skipped for some reason, for example, because it was unreadable or not found. The warning message will give details. SEE ALSO
lintian(1). AUTHOR
checkbashisms was originally written as a shell script by Yann Dirson <dirson@debian.org> and rewritten in Perl with many more features by Julian Gilbey <jdg@debian.org>. DEBIAN
Debian Utilities CHECKBASHISMS(1)
All times are GMT -4. The time now is 10:57 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy