免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 20826 | 回复: 3

求问exp_continue的含义 [复制链接]

论坛徽章:
0
发表于 2012-03-09 17:39 |显示全部楼层
下面这个代码不加exp_continue和不加exp_continue有什么区别?

  1 #!/usr/bin/expect
  2
  3 set passwd "mypassword“
  4
  5
  6 if {$argc != 1} {
  7     send "usage ./account.sh \$newaccount\n"
  8     exit
  9 }
10
11 set user [lindex $argv [expr $argc-1]]
12
13 spawn sudo useradd -s /bin/bash -g mygroup -m $user
14
15 expect {
16     "assword" {
17         send_user "sudo now\n"
18         send "$passwd\n"
19         exp_continue
20     }
21     eof
22     {
23         send_user "eof\n"
24     }
25 }
26
27 spawn sudo passwd $user
28 expect {
29     "assword" {
30         send "$passwd\n"
31         exp_continue
32     }
33     eof
34     {
35         send_user "eof"
36     }
37 }
38
39 spawn sudo smbpasswd -a $user
40 expect {
41     "assword" {
42         send "$passwd\n"
43         exp_continue
44     }
45     eof
46     {
47         send_user "eof"
48     }
49 }


论坛徽章:
3
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:51:162015年亚洲杯之阿曼
日期:2015-04-07 20:00:59
发表于 2012-03-09 20:01 |显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
16
IT运维版块每日发帖之星
日期:2015-08-24 06:20:00综合交流区版块每日发帖之星
日期:2015-10-14 06:20:00IT运维版块每日发帖之星
日期:2015-10-25 06:20:00IT运维版块每日发帖之星
日期:2015-11-06 06:20:00IT运维版块每日发帖之星
日期:2015-12-10 06:20:00平安夜徽章
日期:2015-12-26 00:06:302016猴年福章徽章
日期:2016-02-18 15:30:34IT运维版块每日发帖之星
日期:2016-04-15 06:20:00IT运维版块每日发帖之星
日期:2016-05-21 06:20:00综合交流区版块每日发帖之星
日期:2016-08-16 06:20:002015七夕节徽章
日期:2015-08-21 11:06:17IT运维版块每日发帖之星
日期:2015-08-14 06:20:00
发表于 2012-03-09 20:06 |显示全部楼层
The command exp_continue allows expect itself to continue execut-
             ing rather than  returning  as  it  normally  would.  By  default
             exp_continue  resets  the timeout timer. The -continue_timer flag
             prevents timer from being restarted. (See expect for more  infor-
             mation.)
和其他语言的类似,好吧结合你的例子,sudo passwd 给用户改密码,会2次输入密码的情况,第一次匹配上了,发送密码,此时没有continue,会按照继续向下执行,遇到eof结束。
有了continue,会allows expect itself to continue execut-
             ing rather than  returning  as  it  normally  would
会执行这部分 "assword" {
42         send "$passwd\n"
刚好符合改密码的情况,2次输入。。。。

这东西和c的类似,揣摩一下不难理解,楼主应该加强学习能力啊

论坛徽章:
0
发表于 2015-07-04 10:30 |显示全部楼层
赞。。。学习了。。。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP