安装expect

来源:互联网 发布:淘宝阿沁家是正品吗 编辑:程序博客网 时间:2024/05/08 07:10
一、Linux下expect的安装和使用
    要使用expect需要预先安装tcl这个东西,然后再安装expect包.我这里使用的是tcl8.4.11-src.tar.gz和expect-5.43.0.tar.gz的安装包.
    安装tcl和expect

    #tar zxvf tcl8.4.11-src.tar.gz #cd tcl8.4.11/unix #./configure && make && make install #cp tclUnixPort.h  ../generic/

    #tar zxvf expect-5.43.0.tar.gz #cd expect-5.43/ #./configure --with-tcl=/usr/local/lib/ --with-tclinclude=\ /home/nagios/tcl8.4.11/generic/  --with-x=no

    #make && make install

    OK,tcl以及expect已经安装完成了.下面给出scp的一个expect很简单的一个脚本

    #!/usr/local/bin/expect

    spawn scp /home/nagios/tuning-primer.sh nagios@192.168.100.104:/home/nagios/

    expect "Password:"

    exec sleep 2

    send "nagios&*(\n"

    interact

 

ps: 如果提示缺tk,那么可能需要安装tk;

 

二、Windows下except的安装和使用

    这是一个自动登录AIX服务器的例子。

1、先去如下地方下载expect:
windows">http://expect.nist.gov/#windows
ftp://bmrc.berkeley.edu/pub/winnt/tcltk/expect

2、安装默认路径是C:Program FilesExpect-5.21bin
expect.exe就在这里

3、写个简单的脚本sample.txt
spawn telnet aixserver
expect "login:"
send "mynamer"
expect "Password:"
send "mypassr"
send "lsr"
send "prtconfr"
expect eof

PS:网页的问题,脚本中的“\”等符号会丢失。

4、运行命令expect sample.txt看看效果

5、看看expect的一些帮助信息:
「开始」菜单程序Expect-5.21Tcl 8.0 Shell with Expect
敲?和help看看

 

ps:附相关文件下载地址

tcl:     http://prdownloads.sourceforge.net/tcl/tcl8.4.16-src.tar.gz

tk:      http://prdownloads.sourceforge.net/tcl/tk8.4.16-src.tar.gz

expect:     http://sourceforge.net/projects/expect/files/Expect/5.45/expect5.45.tar.gz/download


原创粉丝点击