码迷,mamicode.com
首页 > 其他好文 > 详细

expect交互式自动化脚本

时间:2015-12-06 19:14:06      阅读:333      评论:0      收藏:0      [点我收藏+]

标签:

一 什么是expect

 1      Expect is a tool for automating interactive applications such as telnet, ftp,
 2  passwd, fsck, rlogin, tip, etc. Expect really makes this stuff trivial. Expect 
 3 is also useful for testing these same applications. And by adding Tk, you 
 4 can also wrap interactive applications in X11 GUIs.
 5 
 6 Expect can make easy all sorts of tasks that are prohibitively difficult with 
 7 anything else. You will find that Expect is an absolutely invaluable tool - 
 8 using it, you will be able to automate tasks that youve never even 
 9 thought of before - and youll be able to do this automation quickly and 
10 easily.

  expect 是一个用于构建交互式自动化(telnet,ftp等)的工具,可以配合tk构建x11gui.expect能把你日常交互的工作变得自动,简单.(CLI下测试网络设备).

二 安装

  expect 基于tcl (怀念以前的tcl,ATF啊,时间过的好快,眨眼快1年了)

  unix系安装   yum -y install tcl expect 敲入 expect

技术分享

  windows安装  http://www.activestate.com/activetcl/downloads  下载自己的版本

技术分享

切换到你的目录tcl/bin/ ,python 包管理是easy_install 和pip ,tcl 的包管理工具是teacup

出现这个问题

 1 C:\windows\system32>teacup.exe install Expect
 2 Resolving Expect ... Not found in the archives.
 3 
 4         While a more fuzzy search disregarding letter case and accepting
 5         substrings was done, we are sorry to say that it yielded no possible
 6         candidates for installation either.
 7 
 8         Questions to consider:
 9                 Have you spelled the name correctly ?
10                 Including the proper case of characters ?
11 
12         Note that teacups search command allows you to locate packages by
13         subject, categories, and the like.
14 
15 
16         Aborting installation, was not able to locate the requested
17         entity.

发现找不到,官网看了下,没有x64版本,x86还是5.43版本. 另外tcl85为了控制包大小,去掉了expect. 84内置了expect,脚本头部package require Expect.想在win上用还是装84吧.

三 实例

  1. 写一个ping 的tcl 脚本

技术分享

运行结果

技术分享

  2. 写一个expect

技术分享

运行结果

技术分享

 

*** 脚本运行前肯定要给执行权限嘛

expect 例子写的不好,大家可以写个模拟smtp163 之类的练手

 

语法参考:

http://www.tcl.tk/man/tcl8.5/tutorial/

http://expect.sourceforge.net/

本站博文皆为原创,转载请标明出处,小三爷在此谢过了~~!

expect交互式自动化脚本

标签:

原文地址:http://www.cnblogs.com/liuyuxing/p/5023995.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!