Encapsulating output of CURL and/or WGET

i use curl and wget quite often.

i set up alarms on their output. for instance, i would run a "wget" on a url and then search for certain strings within the output given by the "wget".

the problem is, i cant get the entire output or response of my wget/curl command to show up correctly in the Nagios GUI.

this is because there are a variety of characters that confuses the GUI. these characters include but aren't limited to: /\[]^& etc. i guess the term for them is "metacharacters".

how can I force it so that ALL ouput produced by a wget or curl is actually shown, down to the very last character?

i.e. for example, the below is the most basic example i can show as to what i want:

OUTPUT=$(wget www.cnn.com)

echo ${OUTPUT}

I would like to be able to show everything that is outputted by the wget, in the format that it was outputted.

this is harder than it sounds.

How about just letting it print instead of continually cramming everything into backticks? You don't have to always have to do that.

Also, how about checking their return codes instead of grepping their output? Every process you create returns an error code for success or failure, and wget is not an exception. If it fails to download a page, it willl tell you so directly. There's no need to grep for 'error' in the output.

If you're downloading multiple pages and wish to see which succeeded via script, wget has the -nv option, which outputs success or failure for individual files in a simple line-by-line list.

The real problem is, they're not one thing, they're two streams. stdout is used for data, stderr is used for errors.

If you want them both to go to stdout: wget ... 2>&1

thank you for the response.

the task i often have to deal with is, some clients request that a specific URL be curled/wgetted and in the output returned, they want to make sure that there is a certain string(s) contained in it.

so in the previous wget example i gave (its just an example), some clients may want to make sure the words "HTTP request sent, awaiting response" is found in the output. in such a case, just checking for the exit code is not good enough. it helps if, when the check alerts, it also contains the full error message.

lets say the exit code is a non-zero. it would help tremendously to actually be able to see what the failure was.

for instance, after running a wget on a URL, the following was returned:

<detail><vXMLVersion>0.0.1</vXMLVersion><addressAndMailPieceInformation><vError>Fatal exception during validationjava.lang.NullPointerException</vError></addressAndMailPieceInformation></detail>

Now, this isn't the typical response. So when the URL check was run and got back this error response, it would help if I can actually show the entire message to the output of the GUI. its very difficult putting this response in a variable and outputting it out the way it alerted.

see what i mean?

Well, you could save the stderr output in a temp file with 2>filename and spit it out only if the data you get doesn't meet certain requirements.