免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 8434 | 回复: 6
打印 上一主题 下一主题

[系统管理] expect wait [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-08-25 10:47 |只看该作者 |倒序浏览
expect 学习
example
spawn telenet IP
expect "login:*"
send "user\r"
expect "password:*"
send "123456\r"
sleep 5

send "service XXXXX start"  # =>假如这个命令执行时间长,命令结果不知道。不用expect , sleep,能不能用wait等待服务启动完成,再查状态。

wait                                       #<= wait 行吗

send "service XXXXX status" #查服务启动状态

expect eof

论坛徽章:
15
2015年辞旧岁徽章
日期:2015-03-03 16:54:15双鱼座
日期:2015-01-15 17:29:44午马
日期:2015-01-06 17:06:51子鼠
日期:2014-11-24 10:11:13寅虎
日期:2014-08-18 07:10:55酉鸡
日期:2014-04-02 12:24:51双子座
日期:2014-04-02 12:19:44天秤座
日期:2014-03-17 11:43:36亥猪
日期:2014-03-13 08:13:51未羊
日期:2014-03-11 12:42:03白羊座
日期:2013-11-20 10:15:18CU大牛徽章
日期:2013-04-17 11:48:45
2 [报告]
发表于 2013-08-27 09:56 |只看该作者
expect 自带wait
  1. wait [args]
  2. delays until a spawned process (or the current process if none is named) terminates.

  3. wait
  4. normally returns a list of four integers. The first integer is the pid of the process that was waited upon. The second integer is the corresponding spawn id. The third integer is -1 if an operating system error occurred, or 0 otherwise. If the third integer was 0, the fourth integer is the status returned by the spawned process. If the third integer was -1, the fourth integer is the value of errno set by the operating system. The global variable errorCode is also set.
  5. Additional elements may appear at the end of the return value from wait. An optional fifth element identifies a class of information. Currently, the only possible value for this element is CHILDKILLED in which case the next two values are the C-style signal name and a short textual description.
复制代码

论坛徽章:
8
摩羯座
日期:2014-11-26 18:59:452015亚冠之浦和红钻
日期:2015-06-23 19:10:532015亚冠之西悉尼流浪者
日期:2015-08-21 08:40:5815-16赛季CBA联赛之山东
日期:2016-01-31 18:25:0515-16赛季CBA联赛之四川
日期:2016-02-16 16:08:30程序设计版块每日发帖之星
日期:2016-06-29 06:20:002017金鸡报晓
日期:2017-01-10 15:19:5615-16赛季CBA联赛之佛山
日期:2017-02-27 20:41:19
3 [报告]
发表于 2013-08-27 13:57 |只看该作者
expect 提示符
send "wait\r"
expect 提示符

论坛徽章:
0
4 [报告]
发表于 2013-08-29 13:59 |只看该作者
waker 发表于 2013-08-27 13:57
expect 提示符
send "wait\r"
expect 提示符


1.
expect 提示符
send "wait\r"

2.
expect 提示符
wait

1.2两个方法有区别吗?

论坛徽章:
8
摩羯座
日期:2014-11-26 18:59:452015亚冠之浦和红钻
日期:2015-06-23 19:10:532015亚冠之西悉尼流浪者
日期:2015-08-21 08:40:5815-16赛季CBA联赛之山东
日期:2016-01-31 18:25:0515-16赛季CBA联赛之四川
日期:2016-02-16 16:08:30程序设计版块每日发帖之星
日期:2016-06-29 06:20:002017金鸡报晓
日期:2017-01-10 15:19:5615-16赛季CBA联赛之佛山
日期:2017-02-27 20:41:19
5 [报告]
发表于 2013-08-29 14:09 |只看该作者
假设你的本机为A
telnet的目标机器为B
那么1中的wait在B上执行
2中的wait在A上执行

论坛徽章:
1
摩羯座
日期:2013-09-28 17:07:31
6 [报告]
发表于 2013-09-10 16:04 |只看该作者
第一种无法满足需要把
回复 4# lll0024


   

论坛徽章:
1
摩羯座
日期:2013-09-28 17:07:31
7 [报告]
发表于 2013-09-10 16:12 |只看该作者
本帖最后由 hanfeng122525 于 2013-09-10 16:16 编辑

用 sleep 需要估计等待的时间,这个有时候估计时间不是那么准确;

用wait,不用估计时间,但是执行完了之后,怎么继续后面的任务;就是结束 wait,而又要保证wait前的任务已经完成。??回复 5# waker


   
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP