0

Here's an excerpt of some commands that I've been trying to evaluate from a Zsh script:

cmd="ping -qc 3 -W 5 8.8.8.8 | xargs -0d '\n' awk -f presetup/testping.awk 2>&1"
print -r ${cmd}
output=$(eval ${cmd})
print ${output}

I don't know what I'm missing but, all I'm trying to do is to process the stderr & stdout of ping with a single awk script. Here's the output I'm getting:

awk: presetup/testping.awk:6: fatal: cannot open file `PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.' for reading (No such file or directory)

The program is supposed to parse each output line of the ping command and match with regular expressions its output. Any ideas of what I'm missing?

Thesevs
  • 51
  • 8
  • 2
    `xargs` is wrong there, you have to pipe stdout and stderr to `awk`. – karakfa Nov 13 '18 at 19:09
  • @karakfa, thanks for your input. I removed `xargs` and tried this: `ping -qc 3 -W 5 8.8.8.8 2>&1 awk -f presetup/testping.awk -` without success. I had the following output: `ping: -: Name or service not known`. – Thesevs Nov 13 '18 at 21:41
  • @karakfa, nevermind, I found it. The right way seems to be the following: `ping -qc 3 -W 5 8.8.8.8 | 2>&1 awk -f presetup/testping.awk -` Thanks for pointing me into the right direction! – Thesevs Nov 13 '18 at 21:48

1 Answers1

0

Thank you so much for pointing me into the right direction @karakfa. It seems that the right way is as follows:

ping -qc 3 -W 5 8.8.8.8 2>&1 | awk -f presetup/testping.awk

OR:

ping -qc 3 -W 5 8.8.8.8 |& awk -f presetup/testping.awk
cafce25
  • 15,907
  • 4
  • 25
  • 31
Thesevs
  • 51
  • 8