Find the answer to your Linux question:
Results 1 to 7 of 7
I am having trouble redirecting I/O for ping when a host does not exist. For instance, Code: ping http://www.123abc.com &> out ping: unknown host http://www.123abc.com is the trouble I'm having. ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Dec 2006
    Posts
    47

    Ping I/O will not redirect


    I am having trouble redirecting I/O for ping when a host does not exist. For instance,

    Code:
    ping http://www.123abc.com &> out
    ping: unknown host http://www.123abc.com
    is the trouble I'm having. I have tried redirecting everything I know, but the command will not run silently nor print anything to the output file. (No, this isn't a problem with > vs >>). I'm trying to ping a list of sites, so I really need an output for every site regardless if it exists or not.

    Thanks!

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,755
    The output is going to stderr, which you are not redirecting. Try this:
    Code:
    ping http://www.123abc.com &> out 2>>out
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    Dec 2006
    Posts
    47
    I swear I did that before and it didn't work. Now it does. (Facepalm)

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,755
    Or as my friend Homer says - Doh!
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  6. #5
    Just Joined!
    Join Date
    Dec 2006
    Posts
    47
    Nope, still an issue. I'm using some nasty regex to strip out the data I want. This doesn't work:

    Code:
    ping -c 1 -W 5 http://www.abc123.com | head -n 2 | sed 's/) 56(84) bytes of data.\|PING \|64 bytes from \|:.*//g' | sed 's/([0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\})\|(//g' &>> pingOut 2>> pingOut

  7. #6
    Just Joined!
    Join Date
    Dec 2006
    Posts
    47
    Anyone? Thanks . . .

  8. #7
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    is this bash or csh? i'm not familiar with csh redirecting...anyway, try this bash version:
    Code:
    ping -c 1 -W 5 http://www.abc123.com 2>&1 | head -n 2 | sed 's/) 56(84) bytes of data.\|PING \|64 bytes from \|:.*//g' | sed 's/([0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\})\|(//g'  >> pingOut 2>&1

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •