有人能帮忙吗?我正尝试通过 ssh 捕获/管道传输来自远程 cisco 路由器的 ping 响应(参见脚本)。一切正常,但只有在 ping 时管道才会首先中断“!”来自路由器目的地的 ping 响应:
routername#ping xxx.xxx.xxx.xxx source loopback xx
Type escape sequence to abort.Sending 5, 100-byte ICMP Echos to xxx.xxx.xxx.xxx, timeout is 2 seconds:
Packet sent with a source address of xxx.xxx.xxx.xxx
!
就这样... 似乎在第一个“!”之后就断了。
这种方法效果很好,可以捕获并返回整个 ping 结果:
ssh "user@$1" 'ping xxx.xxx.xxx.xxx source loopback xx' > log
ssh user@$1 "ping xxx.xxx.xxx.xxx source loopback xx" | tee -a log
但只能作为单行命令。我该怎么做才能捕获整个输出直到结束?
我的脚本:
#!/bin/bash
echo "$1"
var1=$(ssh user@$1 << "ENDSSH"
sh version | incl System image file
sh ip interface INTx | incl MTU
show controllers VDx | incl Speed
sh cellular 0 radio | include RSS
sh cellular 0 netw | include Selected
ping xxx.xxx.xxx.xxx source loopback xx
ENDSSH)
echo "$var1" > log