使用expect脚本从ssh捕获输出

时间:2015-05-07 09:02:25

标签: ssh output send expect cisco

我想在file.txt中捕获我的expect脚本的输出。

#!/usr/bin/expect -f

match_max 10000
set timeout 120
eval spawn ssh 10.0.0.0
set prompt ":|#|\\\$"
interact -o -nobuffer -re $prompt return
send "password\r"
expect ">"
send "sh cdp neighbors detail\r\r                              "
expect ">"
send "\n"
sleep 5

这就是我所拥有的,他从一个开关中读出我的cdp邻居细节。但现在我想将此输出推送到我的目录中的文件中。所以我可以在交换机上自动执行命令,并获得输出。该脚本完全有效,但我找不到足够的信息来读取expect脚本的输出。

提前致谢!

Omnomnom

2 个答案:

答案 0 :(得分:6)

您可以使用log_file

log_file switch.log;# Logging it into the file 'switch.log'

只需在要捕获日志记录的行之前添加该行。有关详细信息,请查看here

答案 1 :(得分:4)

找到它,非常简单:

./expectscript > output.txt 2>&1
相关问题