Re: Expect, telnet, frozen console.

From: Gavin McDonald (gavin_at_advanceforklift.com)
Date: 03/30/04


Date: Tue, 30 Mar 2004 20:01:41 GMT

Hi again,
further to this problem, I have captured the output of strace
both in an instance where the script hangs, and an instance
where it does not. I quote the relevant portions below:

//////////////////BROKEN//////////////////////////

--** ESC PRESSED **--
read(0, "\33", 4096) = 1
write(4, "\33", 1) = 1
select(5, [0 4], [], [0 4], NULL) = 1 (in [4])
read(4, "\33[?25l\33[5;38f "..., 4096) = 54
write(1, "\33[?25l\33[5;38f "..., 54) = 54
select(5, [0 4], [], [0 4], NULL) = 1 (in [4])
read(4, "\33[36;40m\33[36;40m\33[;10;1m\r\33[2J\33[1"..., 4096) = 4016
brk(0x806c000) = 0x806c000
write(1, "\33[36;40m\33[36;40m\33[;10;1m\r\33[2J\33[1"..., 4001) = 4001
gettimeofday({1080673605, 582028}, {480, 0}) = 0
gettimeofday({1080673605, 582229}, {480, 0}) = 0
gettimeofday({1080673605, 582445}, {480, 0}) = 0
select(5, [0], [], [0 4], {0, 0}) = 0 (Timeout)
gettimeofday({1080673605, 583390}, {480, 0}) = 0
gettimeofday({1080673605, 583592}, {480, 0}) = 0
gettimeofday({1080673605, 583786}, {480, 0}) = 0
gettimeofday({1080673605, 583971}, {480, 0}) = 0
gettimeofday({1080673605, 584215}, {480, 0}) = 0
read(4, 0x8065530, 4096) = -1 EIO (Input/output error)
--- SIGCHLD (Child exited) ---
write(1, ".\33[13;48f\33[?25h\0\33[;", 19) = 19
close(4) = 0

//////////////////WORKING//////////////////////////

--** ESC PRESSED **--
read(0, "\33", 4096) = 1
write(4, "\33", 1) = 1
select(5, [0 4], [], [0 4], NULL) = 1 (in [0])
--** ENTER PRESSED **--
read(0, "\r", 4096) = 1
write(4, "\r", 1) = 1
select(5, [0 4], [], [0 4], NULL) = 1 (in [4])
read(4, "\33[?25l\33[5;38f "..., 4096) = 54
write(1, "\33[?25l\33[5;38f "..., 54) = 54
select(5, [0 4], [], [0 4], NULL) = 1 (in [4])
read(4, "\33[36;40m\33[36;40m\33[;10;1m\r\33[2J\33[1"..., 4096) = 4095
brk(0x806c000) = 0x806c000
write(1, "\33[36;40m\33[36;40m\33[;10;1m\r\33[2J\33[1"..., 4001) = 4001
gettimeofday({1080674153, 231103}, {480, 0}) = 0
gettimeofday({1080674153, 231332}, {480, 0}) = 0
gettimeofday({1080674153, 231575}, {480, 0}) = 0
select(5, [0], [], [0 4], {0, 0}) = 0 (Timeout)
gettimeofday({1080674153, 232597}, {480, 0}) = 0
gettimeofday({1080674153, 232824}, {480, 0}) = 0
gettimeofday({1080674153, 233047}, {480, 0}) = 0
gettimeofday({1080674153, 233262}, {480, 0}) = 0
gettimeofday({1080674153, 233532}, {480, 0}) = 0
read(4, ".\33[15;48f\33[?25h", 4096) = 15
write(1, ".\33[13;48f\33[?25h\33[?25l\33[13;48f "..., 109) = 109
gettimeofday({1080674153, 234679}, {480, 0}) = 0
select(5, [0 4], [], [0 4], {0, 0}) = 0 (Timeout)
gettimeofday({1080674153, 235702}, {480, 0}) = 0
gettimeofday({1080674153, 235926}, {480, 0}) = 0
select(5, [0 4], [], [0 4], NULL) = 1 (in [0])
--** SCREEN ACCEPTS INPUT **--
read(0, "B", 4096) = 1

//////////////////END STRACES//////////////////////////

perhaps this will make the problem clearer to someone who
can help. Un fortunately, This is my first foray into
expect, and all the faqs seem to point me here.

tia,
Gavin.

In article <MPG.1ad21d4569d63b17989681@shawnews.vc.shawcable.net>,
gavin@advanceforklift.com says...
> Hi all.
>
> I have Expect v5.38.0/tcl v8.4 on linux 2.4.20 - Slackware 9.0.
>
> I have a simple task I wish to automate:
> telnet into remote host, provide username/password, surrender control to
> user. This script will eventually be tied into /etc/inittab so that it
> can be run in multiple consoles. (Another question in its own time.) The
> script is called with a character and a tty as arguments. The script,
> quoted below, works but hangs in a specific situation;
>
>
> #!/usr/bin/expect --
> log_user 0
> set stty_init "sane cs8 -istrip"
> spawn -nottycopy -nottyinit telnet $HOST
> set tty_spawn_id /dev/[lrange $argv 1 1]
> expect login
> send "$USER[lrange $argv 0 0]\r"
> expect Password
> send "$PASSWORD\r"
> log_user 1
> interact eof
>
> For each $USER on $HOST there are [a..j] logins, named [$USERa..$USERj].
> the command:
> # autologin b tty2
> logs in to $HOST as $USERb. the .profile for said user starts a custom
> app called 'loe' which presents a login screen in 80x24 ASCII a la
> ncurses. (NOT ncurses tho...) from this point, I can login, use the app,
> and all the f-keys, CTRL sequences etc work fine. To back out of a
> screen, the user presses ESC, which also works fine. However, when the
> user presses ESC to back out of the main menu, to the login screen, All
> I/O stops. The cursor disappears, and no further input is accepted. The
> processes stay active however, and if I 'kill -HUP' the telnet process,
> expect exits cleanly. If I telnet manually to the host, this problem
> does not happen at all.
>
> I have compared the output of 'env' for the telnet, and the expect
> logins, and they are identical. It is as though the "login" screen that
> is displayed sends a control character which takes expect out of the
> "interact" command.
>
> I have, on occasion, been able to avoid this by pressing ESC twice, (or
> ESC,ENTER) with enough speed that they transmit before the screen
> redraws. I have also tried removing "eof" from interact, but still the
> problem persists.
>
> The "set stty_init ..." line is an attempt to solve the problem as was
> done here: http://tinyurl.com/ytpse which met with limited, (though