免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
论坛 程序设计 Shell expect
最近访问板块 发新帖
查看: 2478 | 回复: 2
打印 上一主题 下一主题

expect [复制链接]

论坛徽章:
0
1 [报告]
发表于 2011-06-21 17:22 |显示全部楼层
set timeout -1  是什么意思?确定这样写对?
应该是set timeout 1 吧

论坛徽章:
0
2 [报告]
发表于 2011-06-21 17:44 |显示全部楼层
哦,又学习了!
两种方式,如果你这样写的话。需要这样:
     expect {
                "*(yes/no)?*" {send -- "yes\r"; exp_continue}
                "*password:*" {send -- "123456\r"}
                }
expect "]"
send "touch a b c d e\r"
expect "]"
send "exit\r"

或者set timeout 1  ,send password后面也加上exp_continue。我这里需要这样写,因为经常需要跳转两次,就会出现两次yes/no和password

两种方法我测试过了,应该没有问题

论坛徽章:
0
3 [报告]
发表于 2011-06-21 18:19 |显示全部楼层
默认的使用“*”好像是不行的,csh特性,不是十分清楚。
但是使用-re参数后使用单独的“*”是报错的。
老兄,踏踏实实的写进去期待的字符呗,非要完全省事啊?

我提到的两种方法在我机器上测试是没有问题的
  1. [root@bill cu]# more expect.sh
  2. #!/bin/bash
  3. expect << !
  4. set timeout -1
  5. spawn ssh bill@10.2.54.77
  6.      expect {
  7.                 "(yes/no)?" {send -- "yes\r"; exp_continue}
  8.                 "password:" {send -- "123456\r"}
  9.                 }
  10. expect  "]"
  11. send "touch a b c d e\r"
  12. expect  "]"
  13. send "exit\r"
  14. !

  15. [root@bill cu]# sh expect.sh
  16. spawn ssh bill@10.2.54.77
  17. Address 10.2.54.77 maps to bogon, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
  18. bill@10.2.54.77's password:
  19. Last login: Tue Jun 21 18:06:51 2011 from 10.2.54.77
  20. [bill@bill ~]$ touch a b c d e
  21. [bill@bill ~]$ [root@bill cu]#
  22. [root@bill cu]# ll /home/bill/
  23. total 4
  24. -rw-rw-r-- 1 bill bill    0 Jun 21 18:17 a
  25. -rw-rw-r-- 1 bill bill    0 Jun 21 18:17 b
  26. -rw-rw-r-- 1 bill bill    0 Jun 21 18:17 c
  27. -rw-rw-r-- 1 bill bill    0 Jun 21 18:17 d
  28. -rw-rw-r-- 1 bill bill    0 Jun 21 18:17 e
  29. drwxrwxrwx 2 bill bill 4096 Feb 23 04:45 test
  30. [root@bill cu]#
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP