can someone help please? I'm trying to catch/pipe ping response from remote cisco router over ssh (see script). Everything works well but only at ping the pipe brokes at first "!" ping response from router destination:

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

And that's all... It seems to break after the first "!".

Where this works well and catch and give back whole ping result:

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

but only as single line command. What can I do to catch the whole output until end?

My script:

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
echo "$var1" > log
  • Is this the actual code you run? or did you "simplify" it somehow? How do you examine the log file afterwards? Does ssh "user@$1" 'ping xxx.xxx.xxx.xxx source loopback xx' > log work better? Please respond by editing the question. – Kamil Maciorowski Sep 12 at 16:53
  • @KamilMaciorowski : hey kamil.. thank you for response... yours wont work anyway... how i allready mentioned -> other commands work, except ping... which broke the log pipe after the first exclamation mark "!" which is cisco ping response character -> code var1=$(ssh user@$1 << "ENDSSH" sh version | incl System image file sh ip interface INT1 | incl MTU show controllers VDSL | incl Speed sh cellular 0 radio | include RSSI sh cellular 0 netwo | include Selected ENDSSH ) echo "$var1" > log code <- this works fine and i get all data i need... only ping make sick... ;-) – bojan Sep 16 at 14:13
  • Please confirm you invoked my command without changing its syntax, i.e. without a here document and without any intermediate variable. – Kamil Maciorowski Sep 16 at 15:29
  • hey kamil... thank you for reminding... indeed it does working fine... only when i insert it on CLI as one line... how can i pack that in batch with other commands ->> while those !!!! cisco ping feedbacks bash thinks are !! (command history) – bojan Sep 17 at 8:56
  • Why do you think !! triggers history expansion? Are you sure or just guessing? I think your original snippet should not allow this, I really doubt any output can trigger it. History expansion is disabled for non-interactive shells by default. To simplify your problem: why do you need the variable in the first place? Isn't redirecting output to log enough? And to test one strange possibility: what is the output of ssh "user@$1" 'ping xxx.xxx.xxx.xxx source loopback xx' | xxd | grep '!'? – Kamil Maciorowski Sep 17 at 9:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.