【问题标题】:How to save output expect in bash如何在bash中保存输出期望
【发布时间】:2016-07-06 09:55:11
【问题描述】:

我正在尝试制作一个脚本以在 cisco 中保存命令 show version 的输出。

我需要为该 ssh 连接连接到一台服务器,然后我与该设备建立连接。

在out.txt文件中,我有第一个连接的输出,ssh连接,但是我不知道如何保存show version的输出

#!/usr/bin/expect -f
#!/bin/sh
spawn ssh -l user x.x.x.x
expect "login as:"
expect "password:"
send "password\r"
expect "$\r"
send "telnet nemonic\r"
expect "$\r"
expect "login:"
send "user\r"
expect "password:"
send "password\r"
expect "*>"
send "terminal length 0\r"
send "show version \r"
expect "*>"
set results $expect_out(buffer)
set config [open out.txt w]
puts $config $results
close $config
send "exit\r"
expect eof
send  "\r"
send "exit\r"

你能帮帮我吗?

最好的问候

【问题讨论】:

  • 你不能有两个 shebangs。
  • ^^ 话虽如此,我 认为 expect 会将第二行解释为注释并忽略它。整个脚本是纯expect 脚本。
  • expect 工作正常,问题出在输出,只需保存第一个连接,但如果你告诉我,如何在一行中实现,我做到了,谢谢@anishsane

标签: bash expect cisco


【解决方案1】:

我用

解决
log_file -noappend status.txt

在命令显示版本之后

谢谢你&&最好的问候

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-08
    • 1970-01-01
    • 1970-01-01
    • 2021-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-01
    相关资源
    最近更新 更多