免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: expert1
打印 上一主题 下一主题

[学习共享] expect FAQ [复制链接]

论坛徽章:
0
41 [报告]
发表于 2012-07-17 17:00 |只看该作者
学习了,顶一个

论坛徽章:
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
42 [报告]
发表于 2012-07-19 12:26 |只看该作者
回复 38# ljwd1000


    呵呵,没仔细研究过这个Module,您有兴趣搞一个?

论坛徽章:
0
43 [报告]
发表于 2012-07-19 14:38 |只看该作者
本帖最后由 Cloud.D.Ace 于 2012-07-19 14:38 编辑
expert1 发表于 2012-07-19 12:26
回复 38# ljwd1000

LZ有空帮忙看看这个问题:http://bbs.chinaunix.net/thread-3575650-2-1.html

我现在没办法只能不用那个buffer,直接将输出重定向到文件,然后对文件进行操作

论坛徽章:
0
44 [报告]
发表于 2012-07-19 23:20 |只看该作者
突然感觉排版好乱啊……Tom

论坛徽章:
0
45 [报告]
发表于 2012-07-24 16:50 |只看该作者
  1. #file hostlist
  2. #"host"\t"user"\t"password"
  3. #172.16.96.202   root    password1
  4. #172.16.96.203   root    password2

  5. #fabric threading
  6. #http://stackoverflow.com/questions/7798330/how-do-i-ensure-that-a-python-thread-dies-after-its-target-function-completes


  7. from fabric.api import *

  8. host_result = []
  9. host_passwd_result = {}
  10. fd = open('hostlist','r')
  11. for line in fd.readlines():
  12.         str = line.strip()
  13.         str = line.split('\t')
  14.         str[-1] = str[-1].strip()
  15.         add_str = "%s" % (str[0])
  16.         host_result.append(add_str)
  17.         host_passwd_result[str[0]] = str[-1]
  18. fd.close()

  19. env.user = 'root'
  20. env.roledefs['web'] = host_result
  21. env.passwords = host_passwd_result

  22. def comm_ls():
  23.         run('ls /opt')

  24. def comm_whoami():
  25.         run('whoami')

  26. def comm_put():
  27.         put('/tmp/test.txt','/tmp/wiyun.txt')

  28. #exec command with shell
  29. #fab -R web comm_ls comm_whoami -f fab.py
  30. #parallel
  31. #fab -R web comm_ls -P comm_whoami -f fab.py
复制代码
回复 42# expert1


    以前写过的。贴出来,有问题一起讨论。环境安装就不描述了

论坛徽章:
0
46 [报告]
发表于 2012-11-02 18:08 |只看该作者
最近也在写expect交互性脚本,发本贴对我帮助很大。

论坛徽章:
0
47 [报告]
发表于 2013-03-27 18:53 |只看该作者
#!/usr/bin/expect
set timeout 10
set host [lindex $argv 0]
set username [lindex $argv 1]
set password [lindex $argv 2]
spawn ssh $username@$host
expect {
"(yes/no)?"
{
send "yes\n"
expect "*assword:" { send "$password\n" }
}
"*assword:" { send "$password\n" }
expect "*" { send "mkdir 123\n" }
}
expect eof
这个脚本 能登入远程服务器,接下来我想在这台服务器进行一些操作怎么写?

论坛徽章:
0
48 [报告]
发表于 2013-06-29 11:03 |只看该作者
回复 1# expert1

有这样一种情况,若干台服务器因为历史原因,导致有三种密码存在,那么针对IP列表,如何去尝试多个密码呢?
百思不得其解,望LZ能够百忙之中是否可以分析下?谢谢


   

论坛徽章:
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
49 [报告]
发表于 2013-07-11 21:15 |只看该作者
回复 48# xiaochuanjiejie


    可以用expect 的exp_continue,至于python我还不太清楚,等有时间想一下。

论坛徽章:
0
50 [报告]
发表于 2013-08-16 14:07 |只看该作者
既然是说要熟悉TCL,目前自己还不熟悉,暂时瞟一眼
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP