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
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
> 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?
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
> 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...
If I understand you correctly, then just change the line above from:
exp_open [open tty]
to:
exp_open [open /dev/tty8]
Don
> 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?
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