- 论坛徽章:
- 1
|
应用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 |
|