免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3222 | 回复: 0
打印 上一主题 下一主题

[高级应用] VIO学习之expect初步 [复制链接]

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-06-10 18:47 |只看该作者 |倒序浏览

    应用VIO以后,LPAR越来越多,从一个单点管理全局成为工作所必需。单点管理全局,可行的方式有rsh、ssh、expect。rsh不安全,配置工作也多;ssh同样需要在所有LPAR上都安装和配置,麻烦;对比之下,expect只需在一个LAPR上安装就够了。所以经过综合考虑,决定认真学一下expect。掌握expect后,再自动在所有LPAR上安装、配置ssh也就简单了,但掌握expect毕竟是前提。
    先说安装,就是安这三个包:
14:30:50
[email=root@ST-BAT:[/t]#ls]root@ST-BAT:[/t]#ls[/email]
*.rpm
expect-5.42.1-3.aix5.1.ppc.rpm  tcl-8.4.7-3.aix5.1.ppc.rpm      tk-8.4.7-3.aix5.1.ppc.rpm
14:30:58
[email=root@ST-BAT:[/t]root@ST-BAT:[/t[/email]
]#
    安装插曲:
Errors installing expect and tk:
    In some cases you might get an error about failed dependencies when you install the expect and tk RPMs on AIX (for example, error: failed dependencies: libX11.a(shr4.o) is needed by tk-8.3.3-1). Most likely the error occurs because the rpm command does not recognize the shared library. If the error occurs, check to see if the X11 libraries are installed in the directory /usr/lpp/X11/lib. If they are not installed, use the AIX product media to install them. After you have installed the libraries, run the following command. The command enables the rpm command to recognize that the libraries have been installed.
    /usr/sbin/updtvpkg
    When you have run the command, install expect and tk.
    具体命令:
rpm -ivh tcl-8.4.7-3.aix5.1.ppc.rpm
updtvpkg
rpm -ivh tk-8.4.7-3.aix5.1.ppc.rpm
rpm -ivh expect-5.42.1-3.aix5.1.ppc.rpm
    哪里有帮助?不看帮助,不可能学会。
527     export MANPATH=$MANPATH:/opt/freeware/man/
528     man expect
577     cd /opt/freeware/doc/expect-5.42
580     more README
Other interesting scripts are available separately in the directory
http://expect.nist.gov/scripts/
(ftpable as
ftp://ftp.nist.gov/mel/div826/subject/expect/scripts
).  (See below for
how to retrieve these.)  You are welcome to send me scripts to add to
this directory.  A number of Expect scripts are also available in the
Tcl archive, available at
ftp://ftp.neosoft.com/pub/tcl
.
    再补充一个INTERNET上的manpage
http://www.cotse.com/dlf/man/expect/index.html
    哪里有范例?要想学得快,必须多看别人写的例子。
13:38:21
[email=root@ST-BAT:[/opt/freeware/bin]#file]root@ST-BAT:[/opt/freeware/bin]#file[/email]
* | grep -v RISC
autoexpect: shell script  - sh (default shell)
autopasswd: shell script  - sh (default shell)
cryptdir: shell script  - sh (default shell)
decryptdir: shell script  - sh (default shell)
dislocate: shell script  - sh (default shell)
ftp-rfc: shell script  - sh (default shell)
gendiff: shell script  - sh (default shell)
gzexe: shell script  - sh (default shell)
kibitz: shell script  - sh (default shell)
lpunlock: shell script  - sh (default shell)
mkpasswd: shell script  - sh (default shell)
multixterm: shell script  - sh (default shell)
passmass: shell script  - sh (default shell)
rftp: shell script  - sh (default shell)
rlogin-cwd: shell script  - sh (default shell)
timed-read: shell script  - sh (default shell)
timed-run: shell script  - sh (default shell)
tknewsbiff: shell script  - sh (default shell)
tkpasswd: shell script  - sh (default shell)
unbuffer: shell script  - sh (default shell)
weather: shell script  - sh (default shell)
xkibitz: shell script  - sh (default shell)
xpstat: shell script  - sh (default shell)
zcmp: shell script  - sh (default shell)
zgrep: shell script  - sh (default shell)
zmore: shell script  - sh (default shell)
znew: shell script  - sh (default shell)
13:38:27
[email=root@ST-BAT:[/opt/freeware/bin]root@ST-BAT:[/opt/freeware/bin[/email]
]#
    INTERNET上的也有范例:
http://expect.nist.gov/scripts/
http://expect.nist.gov/example/
    最常见的命令:
spawn 用于生成一个子进程运行命令
expect 用于期待一个字符串的出现
send 就是模拟人工输入一个字符串
lindex 可以在数组中选择某个元素
    一个简单的例子,将本机的root密码从root改为root2。
cd /t
cat 1
#!/usr/bin/expect -f
set timeout -1
spawn $env(SHELL)
match_max 100000
send -- "telnet [lindex $argv 0]\r"
expect "login: "
send -- "root\r"
expect "Password: "
send -- "root\r"
send -- "passwd\r"
expect "New password: "
send -- "root2\r"
expect -exact "\r
Enter the new password again:"
send -- "root2\r"
send -- "exit\r"
send -- "exit\r"
expect eof
!
chmod +x 1
./1 127.0.0.1
rm -f 1
========================================================================
任何形式的转载,请写明出处:
email:
beginner@yeah.net
blog:
http://blog.chinaunix.net/index.php?blogId=739
   
http://www.cublog.cn/u/739/
========================================================================



本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/739/showart_734165.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP