- 论坛徽章:
- 0
|
我在expect中执行命令,发现 send带变量的命令,会在最后才会被执行,哪怕它在其它的 send语句之前。
我想请教一下expect在执行命令时,顺序是如何指定的。另外,如果想按顺序的执行带变量的 send命令,应该如何编写expect脚本
我的问题脚本代码如下:
#!/usr/local/bin/expect -f
set timeout 1200
set logname xxxx
set password xxxxxx
spawn telnet 192.168.0.212
expect "login*"
send "$logname\r"
expect "Password:"
send "$password\r"
expect "*]/"
send "[ lindex $argv 0 ]\n"
expect "*]/"
send "ps -el | grep java\n"
expect "*]/"
send "exit\n"
expect eof
执行:
./test.exp ;uname -a
结果:
[002]/ <root> ps -el | grep java
8 S 0 21796 1 0 40 20 6228c0d0 8059 600d81de ? 0:13 java
[002]/ <root> exit
logout
Connection closed by foreign host.
SunOS mps009 5.6 Generic_105181-33 sun4u sparc SUNW,UltraSPARC-IIi-cEngine |
|