【发布时间】:2016-02-24 14:05:05
【问题描述】:
有几个相同的帖子,但我仍然无法让我的期望脚本正常工作。我的意图是自动化一切,但为用户输入密码。所以脚本有3部分:
- 自动登录
- 让用户交互输入密码
- 将控制权交还给 Expect 脚本以继续工作
所以我有将生成的脚本,其中有 3 个读取命令。第一个和最后一个应该由 Expect 填写,第二个我想输入我自己:
#!/bin/ksh
read user?User:
echo "Expect entered the username $user"
read pass?Password:
echo "User entered the password $pass"
read command?"Shell>"
echo "Expect entered the command $command"
我的期望脚本:
#!/usr/bin/expect
spawn ./some_script
expect User
send I-am-expect\r
expect Password
interact
expect Shell
send I-am-expect-again
不幸的是,在我输入密码后,脚本无法继续并进入交互模式:
[root@localhost ~]# ./my-expect
spawn ./some_script
User:I-am-expect
Expect entered the username I-am-expect
Password:i am user
User entered the password i am user
Shell>
最后,当我在“Shell”上输入内容并按 [ENTER] 时,期望退出并出现错误:
Expect entered the command
expect: spawn id exp4 not open
while executing
"expect Shell"
(file "./my-expect" line 7)
[root@localhost ~]#
我感谢对此问题的任何解释或解决方案。我正在使用期望版本 5.45
【问题讨论】:
标签: linux login passwords expect interaction