How do you redirect wget response to standard out?

169

26

I have a crontab that wgets a PHP page every five minutes (just to run some the PHP code), and I want to send the output of the request to standard out, while sending the normal wget output to /dev/null (or otherwise hide it). I couldn't find it in the wget manual.

I'm looking for something like:

wget -o stdout http://whatever.com/page.php > /dev/null

Anyone know?

Sean Adkinson

Posted 2011-08-09T22:13:10.083

Reputation: 1 975

5Mistitled, should be "How do you redirect wget to null?". – Bob Stein – 2014-12-30T13:47:34.077

2@BobStein-VisiBone I think it is titled correctly. I wanted the thing that is wget-ed to go to a stdout, and the normal stdout to go to null (i.e. ignore what it usually prints, and instead print the response body). – Sean Adkinson – 2014-12-31T01:24:08.623

6Oh! I stand corrected. I have started using wget http://example.com/page.php -qO- (That's a capital Oh.) That standard-outputs ONLY the response body. Is that what you wanted? – Bob Stein – 2014-12-31T04:32:20.673

Answers

176

wget -O - http://whatever.com/page.php > /dev/null

or, if you want to redirect standard error output also:

wget -O - http://whatever.com/page.php > /dev/null 2>&1

or, for codegolf :-)

wget -O-

Tomas

Posted 2011-08-09T22:13:10.083

Reputation: 5 107

14You may want to add -nv to avoid the progress indicator overwriting the output. – Tor Klingberg – 2015-11-10T15:25:39.173

1This approach has a problem - if response status is not 200, it doesn't print body. Any thoughts to resolve it? – Imaskar – 2018-08-13T09:24:25.420

97

A simpler version

wget -qO- http://example.com

equivalent to

wget -q -O - http://example.com

where

  • -q turns off the output of log, including error information
  • -O -, equivlalent to -O /dev/stdout, means dump the web page to a file named /dev/stdout.

Martin Wang

Posted 2011-08-09T22:13:10.083

Reputation: 1 123

3The first one works with BusyBox's wget, which is very helpful. I don't think it likes having a space after the O – zymhan – 2019-07-19T15:10:48.150

19

wget -qO /dev/null http://whatever.com/page.php
  • -q to make it quiet
  • -O /dev/null to ignore the page contents

unbeli

Posted 2011-08-09T22:13:10.083

Reputation: 314

7

You can also try:

wget -q -O - http://whatever.com/page.php > /dev/null 

the -q will make it "quiet"

Or have the file go to some temp html page that you don't mind having. whatever.com/tempFile.html

Mberger

Posted 2011-08-09T22:13:10.083

Reputation:

4

wget -O /dev/null http://example.com/

Simon

Posted 2011-08-09T22:13:10.083

Reputation:

-O means "write output to this file" – thomasrutter – 2017-11-14T23:57:07.620

It works on my mac with wget 1.12. – None – 2011-08-09T22:29:24.830

Could you provide some explanation about what your code does? – Tamara Wijsman – 2011-11-05T01:14:05.920