先贴代码 主要我用一个shell脚本实现增加linux用户的功能
1 #!/usr/bin/expect -f
2 #!/bin/sh
3 set password 1
4 set name yiyi
5 set num ""
6 spawn adduser $name
7 set timeout 30;
8 expect {
9 password: {send $password\n;exp_continue};
10 password: {send $password\n;exp_continue};
11 *[]: {send $num\n;exp_continue};
12 *[]: {send $num\n;exp_continue};
13 Phone: {send $num\n;exp_continue};
14 Phone: {send $num\n;exp_continue};
15 Other: {send $num\n;exp_continue};
16 }
17 set timeout 30
18 expect "Is the information correct?"
19 send "Y\r"
20 set timeout 30;
21 send exit\n;
22 expect eof
执行完就以报如下错误求大神解决啊:
expect: spawn id exp6 not open
while executing
"expect "Is the information correct?""
(file "./adduser.sh" line 18)