expect脚本如何获得输出
您好,expect脚本(名字为aaa)大概如下:
Assembly code
终端执行的输出为:
root@tj-lc1 ~ # expect aaa
spawn telnet tj-lc1 15551
Trying 192.168.1.101...
Connected to 192.168.1.101.
Escape character is '^]'.
config show
quit
configuration:
default_request_timeout..........[2000]
default_request_resend_attempts..[3]
Goodbye!
Connection closed by foreign host.
我想修改aaa脚本,将default那两行输出弄到变量或文件里,有什么方法吗?
谢谢
Assembly code
#!/usr/bin/expect spawn telnet 192.168.1.101 2345 sleep 5 send "config show\r" sleep 1 send "quit\r" expect eof
终端执行的输出为:
root@tj-lc1 ~ # expect aaa
spawn telnet tj-lc1 15551
Trying 192.168.1.101...
Connected to 192.168.1.101.
Escape character is '^]'.
config show
quit
configuration:
default_request_timeout..........[2000]
default_request_resend_attempts..[3]
Goodbye!
Connection closed by foreign host.
我想修改aaa脚本,将default那两行输出弄到变量或文件里,有什么方法吗?
谢谢
作者: sunming2008 发布时间: 2011-05-12
通过expect的log_file指令可以保存屏幕输出到一个文件中
#!/usr/bin/expect
spawn telnet tj-lc1 15551
sleep 1
send "config show\r"
send "quit\r"
log_file conf_result
expect eof
exit
但是在Shell脚本中调用expect脚本 原来的输出不能完整的记录到文件中,这个怎么解决呢?
#!/usr/bin/expect
spawn telnet tj-lc1 15551
sleep 1
send "config show\r"
send "quit\r"
log_file conf_result
expect eof
exit
但是在Shell脚本中调用expect脚本 原来的输出不能完整的记录到文件中,这个怎么解决呢?
作者: sunming2008 发布时间: 2011-05-13