expect 的安装

来源:互联网 发布:sql id=@id 编辑:程序博客网 时间:2024/05/18 11:48
一、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

二、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看看

 

 原文地址 http://linux.chinaitlab.com/set/796884.html