使用expect脚本从ssh捕获输出

Omn*_*nom 2 ssh cisco expect send output

我想在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
Run Code Online (Sandbox Code Playgroud)

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

提前致谢!

Omnomnom

Din*_*esh 6

你可以利用log_file.

log_file switch.log;# Logging it into the file 'switch.log'
Run Code Online (Sandbox Code Playgroud)

只需在要捕获日志记录的行之前添加该行.有关更多信息,请查看此处.