I want to capture the output of my expect script in a file.txt.
我想在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
This is what I have, he reads out my cdp neighbors detail from a switch. But now I want to push this output in a file, in my directory. So I can automate doing commands on a switch, and get the output. The script works completely but I can't find enough information to read the output from an expect script.
这就是我所拥有的,他从一个开关中读出我的cdp邻居细节。但现在我想将此输出推送到我的目录中的文件中。所以我可以在交换机上自动执行命令,并获得输出。该脚本完全有效,但我找不到足够的信息来读取expect脚本的输出。
Thanks in advance!
提前致谢!
Omnomnom
2 个解决方案
#1
You can make use of log_file
.
您可以使用log_file。
log_file switch.log;# Logging it into the file 'switch.log'
Just add that before the line from where you want to capture the logging. Have a look at here for more information.
只需在要捕获日志记录的行之前添加该行。有关更多信息,请查看此处。
#2
Found it, very easy:
找到它,很容易:
./expectscript > output.txt 2>&1
#1
You can make use of log_file
.
您可以使用log_file。
log_file switch.log;# Logging it into the file 'switch.log'
Just add that before the line from where you want to capture the logging. Have a look at here for more information.
只需在要捕获日志记录的行之前添加该行。有关更多信息,请查看此处。
#2
Found it, very easy:
找到它,很容易:
./expectscript > output.txt 2>&1