1

I wish to suppress all output to stdout (console) from hping3 from a bash script, but everything I try results in the statistics still being displayed, even tho the individual ping results are suppressed.

I've tried redirecting different ways, command line switch '-q' and nothing works.

Ideas?

hping3 10.1.1.1 -c 1 -q > \dev\null
hping3 10.1.1.1 -c 1 -q > logfile.txt
hping3 10.1.1.1 -c 1 -q 1>\dev\null

All result in the following to the console:

--- 10.1.1.1 hping statistic ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max = 1.1/1.1/1.1 ms
schroeder
  • 276
  • 2
  • 4
  • 15

1 Answers1

2

As @mark-wagner said, the correct syntax is

hping3 10.1.1.1 -c 1 -q >/dev/null 2>&1

This redirects standard output to a bit-bucket file called /dev/null, and then redirects standard error to the same place.

If this was insufficient (for example, output not on standard error or standard out) then you could do this:

( hping3 10.1.1.1 -c 1 -q ) >/dev/null

This should work, no matter where the output is directed - I think.

Mei
  • 4,590
  • 8
  • 45
  • 53
  • This put me on the alternate track of: hping3 10.1.1.1 -c 1 2> /dev/null, which displays the packet results, but not the summary statistics at the end. Thank you everyone. – schroeder Feb 18 '12 at 21:26
  • This article helped to clearify it https://securitythoughts.wordpress.com/2015/04/08/understanding-bash-stdout-stderr-using-hping3/ – HStL Dec 01 '20 at 21:25