From: Eugene Prokopiev <prokopiev@stc.donpac.ru>
To: ALT Linux Community <community@lists.altlinux.org>
Subject: Re: [Comm] Expect
Date: Wed, 22 Nov 2006 20:59:46 +0300
Message-ID: <45649012.8000904@stc.donpac.ru> (raw)
In-Reply-To: <1164215551.12822.1.camel@localhost>
Peter Volkov пишет:
> On Срд, 2006-11-22 at 15:22 +0300, Eugene Prokopiev wrote:
>
>>1) почему скрипт не дожидется \$ ?
>
>
> А вы уверены, что у вас промпт именно такой.
> echo \'$PS1\' # ? ;)
$ echo \'$PS1\'
'[\u@\h \W]\$ '
К желаемому результату привело "\$ "
>>2) почему abort (описанный в мане) - invalid command name?
>
>
> Читайте внимательней man:
> (Note that abort is presumed to be a procedure defined elsewhere in the script.)
>
> В expect такой команды нет.
да, прошу прощения, ошибся
>>3) можно ли упростить код, приняв что-то вроде "timeout { abort }" за
>>поведение по умолчанию, чтобы в основном коде остались только expect и send?
>
>
> Можно. expect_before или expect_after именно те тулзы, которые вам
> помогут в этом.
В чем-то помогают:
#!/usr/bin/expect -f
if "$argc > 0" {
set hostname [lindex $argv 0]
set username [lindex $argv 1]
set password [lindex $argv 2]
}
set timeout 5
spawn telnet $hostname
expect_after {
timeout { send_user "\nexecution error\n" ; exit 2 }
}
expect {
"login: " { send "$username\r" }
}
expect {
"Password: " { send "$password\r" }
}
expect {
"\$ " { send "ls\r" }
}
expect {
"\$ " { send "exit\r" }
}
expect eof
send_user "executed\n"
exit 0
Но остается необходимость в коде, обрамляющем send "ls\r" и send
"exit\r". Поскольку он дублируется, то хотелось бы от него избавиться.
Т.е. в основном коде мы просто передаем данные, а проверка на наличие
приглашения (или какого-то признака удачного выполнения) осуществляется
сама собой. Правильно ли я понял, что send этого не умеет, и придется
писать обертку с send и expect внутри?
--
С уважением, Прокопьев Евгений
next prev parent reply other threads:[~2006-11-22 17:59 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-11-22 12:22 Eugene Prokopiev
2006-11-22 17:12 ` Peter Volkov
2006-11-22 17:59 ` Eugene Prokopiev [this message]
2006-11-23 7:23 ` Eugene Prokopiev
2006-11-23 7:58 ` Eugene Prokopiev
2006-11-23 8:25 ` Eugene Prokopiev
2006-11-23 9:35 ` Eugene Prokopiev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=45649012.8000904@stc.donpac.ru \
--to=prokopiev@stc.donpac.ru \
--cc=community@lists.altlinux.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
ALT Linux Community general discussions
This inbox may be cloned and mirrored by anyone:
git clone --mirror http://lore.altlinux.org/community/0 community/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 community community/ http://lore.altlinux.org/community \
mandrake-russian@linuxteam.iplabs.ru community@lists.altlinux.org community@lists.altlinux.ru community@lists.altlinux.com
public-inbox-index community
Example config snippet for mirrors.
Newsgroup available over NNTP:
nntp://lore.altlinux.org/org.altlinux.lists.community
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git