Mailing List Archive

Problems exec consoles using expect scripts
Hi,

When using consoles that are exec-ing expect scripts, I get troubles
like line buffering of input and local echo. I have the following
console definitions:

console test-ssh {
master localhost;
type exec;
exec "ssh server";
}
console test-expect {
master localhost;
type exec;
exec "expect-console";
}

Where the script "expect-console" contains only the following:

---
#!/usr/bin/expect --
spawn ssh server
interact
---

The conserver user's ssh key is installed on "server", so both consoles
connect fine and I get a shell on "server". However, on the
"test-expect" console input is being line buffered and I get local echo.
So if I e.g. run mc, arrow up/down key presses to navigate the menus
doesn't get registered until I press the enter key, at which point
everything happens as once. (However, the arrow up/down keypresses gets
echoed back to the console immediately as ^[OA / ^[OB and similar
garbage.) Same with using e.g. "less", in order to go to the next page,
I have to press space+enter, and q+enter to quit. If I do "su", the
password I enter gets echoed back to me.

I am pretty sure this is not ssh's fault, as I can replace the ssh
command with an "ipmitool sol activate" command and get the exact same
behaviour.

However, if I run the "expect-console" script directly from the shell on
the server running conserver, it works perfectly. It's only when the
script is invoked from within conserver that the problems occur.

Have anyone experienced this issue and/or have any suggestions on how to
fix it? If so that would be greatly appreciated!

I'm running Ubuntu 12.04 x86_64 with the distribution packages of both
conserver (version 8.1.18) and expect (version 5.45), for what it's worth.

Best regards,
Tore Anderson
_______________________________________________
users mailing list
users@conserver.com
https://www.conserver.com/mailman/listinfo/users
Re: Problems exec consoles using expect scripts [ In reply to ]
I ran into a problem like this a while back.

What I did is write a program that would execute the script on a pseudo
tty. That program sets up the master and slave ptys appropriately.

Chris
_______________________________________________
users mailing list
users@conserver.com
https://www.conserver.com/mailman/listinfo/users
Re: Problems exec consoles using expect scripts [ In reply to ]
On 04 December, 2013 - Chris Fowler wrote:

> I ran into a problem like this a while back.
>
> What I did is write a program that would execute the script on a pseudo tty.
> That program sets up the master and slave ptys appropriately.
>

I just solved it by exec'ing ssh -tt directly. That forces ssh to
allocate a pty in the other end and do all the processing there.

//Anton

--
Anton Lundin +46702-161604
_______________________________________________
users mailing list
users@conserver.com
https://www.conserver.com/mailman/listinfo/users
Re: Problems exec consoles using expect scripts [ In reply to ]
I just ran a similar test on my mac (easiest thing with expect at this point), and all seemed mostly well (no line buffering/echo issues). Conserver does (or is supposed to, if it detects support) allocate pseudo-ttys when execing consoles. In the past, it's worked on Solaris and Linux, but I haven't tested or looked at how it behaves in quite a while.

Guess it's time to build an Ubuntu VM...

Bryan
_______________________________________________
users mailing list
users@conserver.com
https://www.conserver.com/mailman/listinfo/users
Re: Problems exec consoles using expect scripts [ In reply to ]
* Bryan Stansell

> I just ran a similar test on my mac (easiest thing with expect at
> this point), and all seemed mostly well (no line buffering/echo
> issues). Conserver does (or is supposed to, if it detects support)
> allocate pseudo-ttys when execing consoles. In the past, it's worked
> on Solaris and Linux, but I haven't tested or looked at how it
> behaves in quite a while.

It does indeed appear to do so:

tore@conserver:~$ console -x | grep test
test-expect on /dev/pts/0 at Local
test-ssh on /dev/pts/19 at Local

Also, to comment on Anton's suggestion to use "ssh -tt" - this yields
the exact same results as without. If I add "-v" to the ssh command line
I can confirm that the ssh client reports "debug1: Entering interactive
session." both when it's being run directly and when it's being started
from expect.

Tore
_______________________________________________
users mailing list
users@conserver.com
https://www.conserver.com/mailman/listinfo/users
Re: Problems exec consoles using expect scripts [ In reply to ]
Good news is I was able to replicate the issue on my shiny new Ubuntu VM. I haven't got a clue why it's happening, though I haven't dug in much. More poking around as I have time...

Bryan

On Dec 4, 2013, at 3:01 PM, Bryan Stansell <bryan@conserver.com> wrote:
> Guess it's time to build an Ubuntu VM...
>
> Bryan


_______________________________________________
users mailing list
users@conserver.com
https://www.conserver.com/mailman/listinfo/users
Re: Problems exec consoles using expect scripts [ In reply to ]
I do what the original poster does, but I use PERL with Expect.

Bryan Stansell <bryan@conserver.com> wrote:
>Good news is I was able to replicate the issue on my shiny new Ubuntu
>VM. I haven't got a clue why it's happening, though I haven't dug in
>much. More poking around as I have time...
>
>Bryan
>
>On Dec 4, 2013, at 3:01 PM, Bryan Stansell <bryan@conserver.com> wrote:
>> Guess it's time to build an Ubuntu VM...
>>
>> Bryan
>
>
>_______________________________________________
>users mailing list
>users@conserver.com
>https://www.conserver.com/mailman/listinfo/users
Re: Problems exec consoles using expect scripts [ In reply to ]
* Bryan Stansell

> Good news is I was able to replicate the issue on my shiny new Ubuntu
> VM. I haven't got a clue why it's happening, though I haven't dug in
> much. More poking around as I have time...

Hi Bryan,

Now that the holidays are past us, I was wondering if you did find out
anything more about this issue?

Best regards,
Tore Anderson
_______________________________________________
users mailing list
users@conserver.com
https://www.conserver.com/mailman/listinfo/users
Re: Problems exec consoles using expect scripts [ In reply to ]
Sorry, I haven't had a chance yet. But thanks for the reminder - I'v got the VM running again and I'll start poking at it...

Bryan

On Jan 8, 2014, at 1:38 AM, Tore Anderson <tore@fud.no> wrote:

> * Bryan Stansell
>
>> Good news is I was able to replicate the issue on my shiny new Ubuntu
>> VM. I haven't got a clue why it's happening, though I haven't dug in
>> much. More poking around as I have time...
>
> Hi Bryan,
>
> Now that the holidays are past us, I was wondering if you did find out
> anything more about this issue?
>
> Best regards,
> Tore Anderson


_______________________________________________
users mailing list
users@conserver.com
https://www.conserver.com/mailman/listinfo/users
Re: Problems exec consoles using expect scripts [ In reply to ]
Well, I was successful enough to dig up what's going on and a way of working around it, but I still don't understand the underlying issue (which is turning into: why is the Ubuntu distribution working differently than CentOS, MacOSX, and Solaris).

The issue, seen from traces, is that expect is not able to open /dev/tty on Ubuntu when running under conserver (which releases the controlling tty, etc when daemonizing). Apparently expect does some manipulations of the tty modes when it has access to /dev/tty and for an unknown reason to me, it is being denied on Ubuntu. Because of this, it's not setting it's own ptys into a "passthrough" mode (raw, no echo, etc). So, you end up with two layers of processing happening and all the goofiness you see (echoed commands, control characters printed but also "working", etc).

I took a snapshot of the tty settings on CentOS and, by using them, you can do this missing work for expect within the expect script. All I did was add

exec stty 0:0:bf:0:3:1c:8:40:4:0:1:0:11:13:1a:0:12:f:17:16:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0

to the top of the expect script and those magic entries reset things to the proper modes. I also had basic success using "exec stty raw -echo". Using the symbolic names is safer and what I recommend, but I'll leave it up to you to enumerate all the settings to make a complete set. I was looking for the easy way out. :-/

So the big question is: why is Ubuntu not playing like the other kids on the block. Maybe /dev/tty access is enforced differently, maybe the daemonization process is resulting in different process states (more or less "cleansed"), etc. Not sure I'm going to dig into it, but if someone tracks down the root cause, and it's something conserver is doing wrong (which would be surprising to me as I know folks have been using expect with conserver a long time - but you never know), I'm up for any pointers or patches.

Hopefully this gets you going and helps anyone else that might trip up here. If this workaround doesn't work for you, that would be good to know too, of course.

Bryan

On Jan 8, 2014, at 8:09 AM, Bryan Stansell <bryan@conserver.com> wrote:

> Sorry, I haven't had a chance yet. But thanks for the reminder - I'v got the VM running again and I'll start poking at it...
>
> Bryan
>
> On Jan 8, 2014, at 1:38 AM, Tore Anderson <tore@fud.no> wrote:
>
>> * Bryan Stansell
>>
>>> Good news is I was able to replicate the issue on my shiny new Ubuntu
>>> VM. I haven't got a clue why it's happening, though I haven't dug in
>>> much. More poking around as I have time...
>>
>> Hi Bryan,
>>
>> Now that the holidays are past us, I was wondering if you did find out
>> anything more about this issue?
>>
>> Best regards,
>> Tore Anderson
>
>
> _______________________________________________
> users mailing list
> users@conserver.com
> https://www.conserver.com/mailman/listinfo/users


_______________________________________________
users mailing list
users@conserver.com
https://www.conserver.com/mailman/listinfo/users
Re: Problems exec consoles using expect scripts [ In reply to ]
* Bryan Stansell

> Hopefully this gets you going and helps anyone else that might trip
> up here.

Indeed it does, thank you very much!

I'd submit a bug report to Ubuntu, if it wasn't for the fact that I have
no idea which package it would be appropriate to assign it to...

Tore
_______________________________________________
users mailing list
users@conserver.com
https://www.conserver.com/mailman/listinfo/users