Need help with expect

  • Follow


Hi,
I'm looking for any way to accessing a menu (created with Cache' in
AIX) and log all data showed
in this menu to a file.
I know how access this menu using expect, but I don't know how log all
data showed
in this menu to a file.

Is there any way to make this task using expect ?

Thanks
0
Reply contracer11 (156) 1/20/2011 11:14:47 AM

On Thu, 20 Jan 2011 03:14:47 -0800, contracer wrote:

> Hi,
> I'm looking for any way to accessing a menu (created with Cache' in AIX)
> and log all data showed
> in this menu to a file.
> I know how access this menu using expect, but I don't know how log all
> data showed
> in this menu to a file.
> 
> Is there any way to make this task using expect ?
> 
> Thanks

For a crude way, either run your expect script inside something else that 
logs all the output, e.g. 'script' or an 'xterm' with logging turned on, 
or use the 'log_file' command of expect (and maybe 'log_user').

A more targeted approach is to use the 'expect' command to look for the 
menu, and then extract it from the 'expect_out' array. You can then use 
standard 'tcl' tools to write it to a file or do whatever else you 
actually want to do with the data.
0
Reply Icarus 1/20/2011 3:29:11 PM



Icarus Sparry wrote:
> On Thu, 20 Jan 2011 03:14:47 -0800, contracer wrote:
>
> > Hi,
> > I'm looking for any way to accessing a menu (created with Cache' in AIX=
)
> > and log all data showed
> > in this menu to a file.
> > I know how access this menu using expect, but I don't know how log all
> > data showed
> > in this menu to a file.
> >
> > Is there any way to make this task using expect ?
> >
> > Thanks
>
> For a crude way, either run your expect script inside something else that
> logs all the output, e.g. 'script' or an 'xterm' with logging turned on,
> or use the 'log_file' command of expect (and maybe 'log_user').
>
> A more targeted approach is to use the 'expect' command to look for the
> menu, and then extract it from the 'expect_out' array. You can then use
> standard 'tcl' tools to write it to a file or do whatever else you
> actually want to do with the data.


Thanks a lot for your help.
I=B4m using log_file command and this command log all data to a file.
Now I need remove all control characters (graphical characters) from
this file, and I don=B4t know how.

0
Reply contracer 1/20/2011 4:42:26 PM

On Thu, 20 Jan 2011 08:42:26 -0800, contracer wrote:

> Icarus Sparry wrote:
>> On Thu, 20 Jan 2011 03:14:47 -0800, contracer wrote:
>>
>> > Hi,
>> > I'm looking for any way to accessing a menu (created with Cache' in
>> > AIX) and log all data showed
>> > in this menu to a file.
>> > I know how access this menu using expect, but I don't know how log
>> > all data showed
>> > in this menu to a file.
>> >
>> > Is there any way to make this task using expect ?
>> >
>> > Thanks
>>
>> For a crude way, either run your expect script inside something else
>> that logs all the output, e.g. 'script' or an 'xterm' with logging
>> turned on, or use the 'log_file' command of expect (and maybe
>> 'log_user').
>>
>> A more targeted approach is to use the 'expect' command to look for the
>> menu, and then extract it from the 'expect_out' array. You can then use
>> standard 'tcl' tools to write it to a file or do whatever else you
>> actually want to do with the data.
> 
> 
> Thanks a lot for your help.
> I´m using log_file command and this command log all data to a file. Now
> I need remove all control characters (graphical characters) from this
> file, and I don´t know how.

You probably don't want to 'remove all control characters', instead you 
probably want to extract useful text from the menu. There is no universal 
way of knowing how to do this, it depends of the system, and probably on 
the terminal type.

To do this you will want to remove sequences which turn on and off 
highlighting, clear to end of line or screen. You will need to see if 
there are cursor movements, and if so interpret them, and so on.

These days one can pretty much assume that the terminal will respond to 
some superset (or subset) of vt100 commands (aka ansi). The expect book 
gives some example code for an expectk program that behaves in this way. 
You can take this code and use it to create an virtual terminal and then 
you can read the characters from this to see what is displayed. Someone 
elase has already done most of the work for you, a quick google search 
for 'virterm' gets me http://www.opensource.apple.com/source/expect/
expect-1/expect/example/virterm as one copy of it.

The other approach is to hope that the output is pretty much written top 
to bottom on the screen, and that it is using a 7bit data path, and just 
change anything matching the regular expression \033\[[^a-zA-Z]*[a-zA-Z] 
(that is an 'escape' character, an '[' character, then any sequence of 
characters that are not letters (in particular numbers and semicolons) 
followed by a letter) with a newline and then see if the data makes sense.

If this sounds complicated, and "I just want to read what is on the 
screen in front of me", remember it takes babies many years to get to the 
stage that they can read what is on the screen.
0
Reply Icarus 1/20/2011 6:08:08 PM

In article <4d387a08$0$22150$742ec2ed@news.sonic.net>,
Icarus Sparry  <i.sparry+un@gmail.com> wrote:
....
>These days one can pretty much assume that the terminal will respond to 
>some superset (or subset) of vt100 commands (aka ansi). The expect book 
>gives some example code for an expectk program that behaves in this way. 
>You can take this code and use it to create an virtual terminal and then 
>you can read the characters from this to see what is displayed. Someone 
>elase has already done most of the work for you, a quick google search 
>for 'virterm' gets me http://www.opensource.apple.com/source/expect/
>expect-1/expect/example/virterm as one copy of it.

I think I might be interested in this 'virterm' thingie, but I have to
admit that I can't figure out from looking at it (from the URL given
above) what it is actually supposed to do.

Can you elaborate some upon this - as to what it is for?

Also, what is tkterm for?

-- 
Religion is regarded by the common people as true,
	by the wise as foolish,
	and by the rulers as useful.

(Seneca the Younger, 65 AD)

0
Reply gazelle 1/20/2011 6:58:10 PM

On Jan 20, 4:58=A0pm, gaze...@shell.xmission.com (Kenny McCormack)
wrote:
> In article <4d387a08$0$22150$742ec...@news.sonic.net>,
> Icarus Sparry =A0<i.sparry...@gmail.com> wrote:
> ...
>
> >These days one can pretty much assume that the terminal will respond to
> >some superset (or subset) of vt100 commands (aka ansi). The expect book
> >gives some example code for an expectk program that behaves in this way.
> >You can take this code and use it to create an virtual terminal and then
> >you can read the characters from this to see what is displayed. Someone
> >elase has already done most of the work for you, a quick google search
> >for 'virterm' gets mehttp://www.opensource.apple.com/source/expect/
> >expect-1/expect/example/virterm as one copy of it.
>
> I think I might be interested in this 'virterm' thingie, but I have to
> admit that I can't figure out from looking at it (from the URL given
> above) what it is actually supposed to do.
>
> Can you elaborate some upon this - as to what it is for?
>
> Also, what is tkterm for?
>
> --
> Religion is regarded by the common people as true,
> =A0 =A0 =A0 =A0 by the wise as foolish,
> =A0 =A0 =A0 =A0 and by the rulers as useful.
>
> (Seneca the Younger, 65 AD)

When I try open this file with vi, I get:
x7.lis" Line too long

Is there any way to create a multi line file ?
0
Reply contracer 1/20/2011 7:20:12 PM

On Jan 20, 5:20=A0pm, contracer <contrace...@gmail.com> wrote:
> On Jan 20, 4:58=A0pm, gaze...@shell.xmission.com (Kenny McCormack)
> wrote:
>
>
>
>
>
> > In article <4d387a08$0$22150$742ec...@news.sonic.net>,
> > Icarus Sparry =A0<i.sparry...@gmail.com> wrote:
> > ...
>
> > >These days one can pretty much assume that the terminal will respond t=
o
> > >some superset (or subset) of vt100 commands (aka ansi). The expect boo=
k
> > >gives some example code for an expectk program that behaves in this wa=
y.
> > >You can take this code and use it to create an virtual terminal and th=
en
> > >you can read the characters from this to see what is displayed. Someon=
e
> > >elase has already done most of the work for you, a quick google search
> > >for 'virterm' gets mehttp://www.opensource.apple.com/source/expect/
> > >expect-1/expect/example/virterm as one copy of it.
>
> > I think I might be interested in this 'virterm' thingie, but I have to
> > admit that I can't figure out from looking at it (from the URL given
> > above) what it is actually supposed to do.
>
> > Can you elaborate some upon this - as to what it is for?
>
> > Also, what is tkterm for?
>
> > --
> > Religion is regarded by the common people as true,
> > =A0 =A0 =A0 =A0 by the wise as foolish,
> > =A0 =A0 =A0 =A0 and by the rulers as useful.
>
> > (Seneca the Younger, 65 AD)
>
> When I try open this file with vi, I get:
> x7.lis" Line too long
>
> Is there any way to create a multi line file ?- Hide quoted text -
>
> - Show quoted text -

How could I remove all data between the "10H" string ?
10HFOLLOWUP(SCRITORY).............. 6920-IFF/FB    20/01/1122M10H
0
Reply contracer 1/20/2011 7:46:03 PM

On Thu, 20 Jan 2011 18:58:10 +0000, Kenny McCormack wrote:

> In article <4d387a08$0$22150$742ec2ed@news.sonic.net>, Icarus Sparry 
> <i.sparry+un@gmail.com> wrote: ...
>>These days one can pretty much assume that the terminal will respond to
>>some superset (or subset) of vt100 commands (aka ansi). The expect book
>>gives some example code for an expectk program that behaves in this way.
>>You can take this code and use it to create an virtual terminal and then
>>you can read the characters from this to see what is displayed. Someone
>>elase has already done most of the work for you, a quick google search
>>for 'virterm' gets me http://www.opensource.apple.com/source/expect/
>>expect-1/expect/example/virterm as one copy of it.
> 
> I think I might be interested in this 'virterm' thingie, but I have to
> admit that I can't figure out from looking at it (from the URL given
> above) what it is actually supposed to do.
> 
> Can you elaborate some upon this - as to what it is for?
> 
> Also, what is tkterm for?

Let me try.

Normally with 'expect' (the program) you simulate the input that a human 
would give to it. You do this by using 'send' (or 'exp_send') commands to 
send the characters that the human would type and you use 'expect' (the 
command) to look for things in the output, e.g. prompts.

The program in the book, and the extended version at the url I pointed at 
have a series of 'expect' commands to look for vt100 control sequences, 
such as
       Escape [ 0 ; 0 H
which moves the cursor to the top left of the screen. Internally the 
program has a 24x80 array of characters and a virtual cursor, and the 
array and cursor get moved in response to every character received.

The example program that is at the end of virterm logs you into a 
particular library catalog, issues a query on your behalf, lets the 
catalog program send you a screen of output, "scrapes" the "screen" (the 
array of characters) to get the useful information off it, sees if the 
catalog program is saying something like "press space for next screen", 
and if so sends a space character to it, scrapes the next screenfull of 
information and so on.

tkterm is a similar. It uses "Tk", an X11 toolkit, to store (and usually 
display) the text in a text "widget" rather than a tcl array. This 
restricts its use to places where you are running an X server (it might 
be one driving a virtual screen such as Xvnc).
0
Reply Icarus 1/20/2011 10:50:49 PM

In article <4d38bc49$0$22093$742ec2ed@news.sonic.net>,
Icarus Sparry  <i.sparry+un@gmail.com> wrote:
....
>> Can you elaborate some upon this - as to what it is for?
>> 
>> Also, what is tkterm for?
>
>Let me try.
>
>Normally with 'expect' (the program) you simulate the input that a human 
>would give to it. You do this by using 'send' (or 'exp_send') commands to 
>send the characters that the human would type and you use 'expect' (the 
>command) to look for things in the output, e.g. prompts.
>
>The program in the book, and the extended version at the url I pointed at 
>have a series of 'expect' commands to look for vt100 control sequences, 
>such as
>       Escape [ 0 ; 0 H
>which moves the cursor to the top left of the screen. Internally the 
>program has a 24x80 array of characters and a virtual cursor, and the 
>array and cursor get moved in response to every character received.
>
>The example program that is at the end of virterm logs you into a 
>particular library catalog, issues a query on your behalf, lets the 
>catalog program send you a screen of output, "scrapes" the "screen" (the 
>array of characters) to get the useful information off it, sees if the 
>catalog program is saying something like "press space for next screen", 
>and if so sends a space character to it, scrapes the next screenfull of 
>information and so on.

OK - thanks.  That makes sense to me.

-- 
They say compassion is a virtue, but I don't have the time!

    - David Byrne -

0
Reply gazelle 1/20/2011 10:58:51 PM

In article <5750fe32-91c0-4a6e-a907-7ce4f12a8e56@s5g2000yqm.googlegroups.com>,
contracer  <contracer11@gmail.com> wrote:
>On Jan 20, 5:20�pm, contracer <contrace...@gmail.com> wrote:
>> On Jan 20, 4:58�pm, gaze...@shell.xmission.com (Kenny McCormack)
>> wrote:
>>
>>
>>
>>
>>
>> > In article <4d387a08$0$22150$742ec...@news.sonic.net>,
>> > Icarus Sparry �<i.sparry...@gmail.com> wrote:
>> > ...
>>
>> > >These days one can pretty much assume that the terminal will respond to
>> > >some superset (or subset) of vt100 commands (aka ansi). The expect book
>> > >gives some example code for an expectk program that behaves in this way.
>> > >You can take this code and use it to create an virtual terminal and then
>> > >you can read the characters from this to see what is displayed. Someone
>> > >elase has already done most of the work for you, a quick google search
>> > >for 'virterm' gets mehttp://www.opensource.apple.com/source/expect/
>> > >expect-1/expect/example/virterm as one copy of it.
>>
>> > I think I might be interested in this 'virterm' thingie, but I have to
>> > admit that I can't figure out from looking at it (from the URL given
>> > above) what it is actually supposed to do.
>>
>> > Can you elaborate some upon this - as to what it is for?
>>
>> > Also, what is tkterm for?
>>
>> > --
>> > Religion is regarded by the common people as true,
>> > � � � � by the wise as foolish,
>> > � � � � and by the rulers as useful.
>>
>> > (Seneca the Younger, 65 AD)
>>
>> When I try open this file with vi, I get:
>> x7.lis" Line too long
>>
>> Is there any way to create a multi line file ?- Hide quoted text -
>>
>> - Show quoted text -
>
>How could I remove all data between the "10H" string ?
>10HFOLLOWUP(SCRITORY).............. 6920-IFF/FB    20/01/1122M10H

FWIW, when I used "wget" to fetch that URL, I had to do a fair amount of
hacking on the resulting file to make it usable as a program.

I had to use vi to trim off a bunch of html crud at the beginning and at
the end - then I used a little script (that I wrote some time back)
called "de-html" to convert things like "&amp;" to "&".

But I am pretty sure that I do have a clean (usable) copy now.

-- 
Just for a change of pace, this sig is *not* an obscure reference to
comp.lang.c...

0
Reply gazelle 1/20/2011 11:01:11 PM

On Thu, 20 Jan 2011 18:08:08 +0000, Icarus Sparry wrote:
I see contracer has posted a couple more articles on this subject, but 
"pan" will not show them as they contain invalid utf-8.

Reading them on google, I see the following questions.

>When I try open this file with vi, I get:
>x7.lis" Line too long
>
>Is there any way to create a multi line file ?

Yes. One approach would be

tr '\033' '\n' < file_with_line_too_long > file_with_shorter_lines

which will change all escape characters into newline characters.

The other question is

> How could I remove all data between the "10H" string ?
> 10HFOLLOWUP(SCRITORY).............. 6920-IFF/FB    20/01/1122M10H 

it depends on what tools you have, vi can do it. As I said I suspect
that there are more characters there than you are showing us.
0
Reply Icarus 1/20/2011 11:01:19 PM

On Thu, 20 Jan 2011 23:01:11 +0000, Kenny McCormack wrote:

> FWIW, when I used "wget" to fetch that URL, I had to do a fair amount of
> hacking on the resulting file to make it usable as a program.
> 
> I had to use vi to trim off a bunch of html crud at the beginning and at
> the end - then I used a little script (that I wrote some time back)
> called "de-html" to convert things like "&amp;" to "&".
> 
> But I am pretty sure that I do have a clean (usable) copy now.

Adding a "?txt" to the end of the URL would probably have been faster, or 
following the "plain text" link at the top.
0
Reply Icarus 1/20/2011 11:34:26 PM

On Thu, 20 Jan 2011 23:01:19 +0000, Icarus Sparry wrote:
> On Thu, 20 Jan 2011 18:08:08 +0000, Icarus Sparry wrote: I see contracer
> has posted a couple more articles on this subject, but "pan" will not
> show them as they contain invalid utf-8.

Usually pan will show such articles, or parts of them, if you 
turn on line wrap or mute quotes.  (Press w or q to toggle those 
options, or click View / Body Pane boxes.)
 
> Reading them on google, I see the following questions.
[...]

-- 
jiw
0
Reply James 1/21/2011 2:09:52 AM

On Jan 21, 12:09=A0am, James Waldby <n...@no.no> wrote:
> On Thu, 20 Jan 2011 23:01:19 +0000, Icarus Sparry wrote:
> > On Thu, 20 Jan 2011 18:08:08 +0000, Icarus Sparry wrote: I see contrace=
r
> > has posted a couple more articles on this subject, but "pan" will not
> > show them as they contain invalid utf-8.
>
> Usually pan will show such articles, or parts of them, if you
> turn on line wrap or mute quotes. =A0(Press w or q to toggle those
> options, or click View / Body Pane boxes.)
>
> > Reading them on google, I see the following questions.
>
> [...]
>
> --
> jiw

How could I remove all data between the "10H" string ?
10HFOLLOWUP(SCRITORY).............. 6920-IFF/FB    20/01/1122M10H
I need a command , not vi.
These file haves a lot of these data, in a long line.


0
Reply contracer 1/21/2011 2:23:48 AM

On Thu, 20 Jan 2011 18:23:48 -0800, contracer wrote:
....
> How could I remove all data between the "10H" string ?
> 10H'.............. 6920-IFF/FB    20/01/1122M10H
> I need a command , not vi.
> These file haves a lot of these data, in a long line.

If by 'between the "10H" string' you mean from FOLLOWUP through 
to 1122M, sed or awk will work; eg if the data is in file ff,
and if the 10H are at beginning and end of line, then
   sed 's/^10H.*10H$/10H10H/' ff
would change each line like the above to   10H10H  .
Is that what you want?  It doesn't seem useful.

It wasn't clear to me (from your earlier message that said
"When I try open this file with vi, I get: x7.lis Line too long")
what file you were referring to.  Presumably not the text in
<http://www.opensource.apple.com/source/expect/expect-1/expect/example/virterm>
as it doesn't seem to have 'FOLLOWUP(SCRITORY)' in it.

If you mean a transcript with embedded control sequences, as you
mentioned before, Icarus Sparry explained earlier what to do, and
he also wrote "it depends on what tools you have".  You seem to be 
posting from an MS Windows system which some unix shell tools 
installed, but rather than me speculating perhaps you could just
say what kind of system your files are on, and what tools are
available.  Eg, do you have ed, sed, perl, awk, grep, cut, file,
tr, sh, bash, ksh, etc etc ?

How did the control sequences get into your files?  Are the
sequences like ANSI/VT100 screen controls as discussed before?
Are the files tar files or database files?  If ff is one of
the files, what is the result of the command   file ff   ?

-- 
jiw
0
Reply James 1/21/2011 7:53:45 AM

14 Replies
180 Views

(page loaded in 0.182 seconds)

Similiar Articles:


















7/28/2012 8:53:54 AM


Reply: