Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Automatic expect login script question

16 views
Skip to first unread message

Szymon Lukasik

unread,
Mar 4, 2004, 3:34:35 PM3/4/04
to
Hello everyone,

I want to write a simple expect script which receives as an argument
user's name and his password and automatically authorize him to use
chosen terminal (for example: /dev/tty8)
I tried something like this:
------------------------------
#!/usr/bin/expect -f
# script log
# usage: log username password

set username [lindex $argv 0]
set pwd [lindex $argv 1]

spawn /sbin/getty 38400 tty8
expect "login:"
send "$username\n"
expect "Password:"
send "$pwd\n"
expect eof
------------------------------
and I receive:
------------------------------
send: spawn id exp4 not open
while executing
"send "$username\n""
(file "./log" line 10)
------------------------------
it's a problem with input for expect I suspect ;)
Anyone knows how to direct expect to read from /dev/tty8 (as in the
example above) ?

Thanks for any suggestions!

Szymon Lukasik

Don Libes

unread,
Mar 5, 2004, 11:56:21 AM3/5/04
to
szy...@poczta.onet.pl (Szymon Lukasik) writes:

I don't believe getty is that flexible that it can read input from
both stdin and then switch to the named tty!

However, you can accomplish what you want with the -u flag to Expect's
interact command. There are some nice examples in the Expect book
showing the same kind of cleverness as you are trying to achieve here.

Don

Szymon Lukasik

unread,
Mar 7, 2004, 6:06:48 PM3/7/04
to
Don Libes <li...@nist.gov> wrote in message news:<s6afzcn...@peace.mel.nist.gov>...
> szy...@poczta.onet.pl (Szymon Lukasik) writes:

> I don't believe getty is that flexible that it can read input from
> both stdin and then switch to the named tty!
>
> However, you can accomplish what you want with the -u flag to Expect's
> interact command. There are some nice examples in the Expect book
> showing the same kind of cleverness as you are trying to achieve here.

> bin
> Don

In the script I want to execute getty and then read the output on the
given terminal (/dev/tty8) and use Expect to authorize automatically
(on /dev/tty8) ... I know that getty calls /bin/login to do that. I
don`t find "interact -u" useful here (maybe because I haven't got that
Expect book:(. Any hints?

Don Libes

unread,
Mar 9, 2004, 10:31:23 AM3/9/04
to
szy...@poczta.onet.pl (Szymon Lukasik) writes:

Basically, you want something like this:

spawn login
exp_open [open tty]
# do password interaction
interact {
-i $proc_id -re .+ {
# send -i $tty_id $expect_out(buffer)
} -i $tty_id -re .+ {
# send -i $proc_id $expect_out(buffer)
}

Clean up any errors I just made and add a few lines to fill in what I
left out (such as the password interaction).

Don

Szymon Lukasik

unread,
Mar 10, 2004, 10:47:44 AM3/10/04
to
Don Libes <li...@nist.gov> wrote in message news:<s6ad67m...@peace.mel.nist.gov>...

> Basically, you want something like this:
>
> spawn login
> exp_open [open tty]
> # do password interaction
> interact {
> -i $proc_id -re .+ {
> # send -i $tty_id $expect_out(buffer)
> } -i $tty_id -re .+ {
> # send -i $proc_id $expect_out(buffer)
> }
>
> Clean up any errors I just made and add a few lines to fill in what I
> left out (such as the password interaction).
>
> Don

I understand Your point of view, but I want to login on different
terminal, than controlling terminal of getty->login... The problem
is how to read/write characters from /dev/tty8 in the script (after
spawning mgetty and in consequence login).
I`m new to Expect, I`m sure it can be done but I don`t know how...

Don Libes

unread,
Mar 10, 2004, 1:52:12 PM3/10/04
to
szy...@poczta.onet.pl (Szymon Lukasik) writes:

If I understand you correctly, then just change the line above from:

exp_open [open tty]

to:

exp_open [open /dev/tty8]

Don

Szymon Lukasik

unread,
Mar 16, 2004, 4:26:38 PM3/16/04
to
Don Libes <li...@nist.gov> wrote in message news:<s6aad2o...@peace.mel.nist.gov>...

> If I understand you correctly, then just change the line above from:
>
> exp_open [open tty]
>
> to:
>
> exp_open [open /dev/tty8]
>
> Don

Hello again,

I hope it is the last time I'm posting another stupid question. I made
my script look like this:

1: set username [lindex $argv 0]
2: set pwd [lindex $argv 1]
3:
4: spawn login
5: set proc_id $spawn_id
6: set tty_id [exp_open [open /dev/tty6]]
7: interact {
8: -i $proc_id -re "login:" {
9: send -i $tty_id $username
10: } -i $tty_id -re "password:" { send -i $proc_id $pwd
11: }
12: }

as a result i'm stuck(hanged) with "spawn login" on my controlling
terminal and nothing happens on /dev/tty8. I don`t know whether I`m
using process descriptors correctly (lines 5,6) & interacting part is
well written?

Don Libes

unread,
Mar 17, 2004, 9:39:46 AM3/17/04
to
szy...@poczta.onet.pl (Szymon Lukasik) writes:

I thought I was pretty clear that this wasn't the complete script.
You need to add a few more flags to direct where the output from each
input should go too. If the man page and examples that come with
Expect aren't enough, I recommend you read the chapter on using
interact with multiple processes. It has explanations and examples of
how to do what you want.

Don

0 new messages