311

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?

5 Answers5

307

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
  • 7,399
  • 31
    You may want to add -nv to avoid the progress indicator overwriting the output. – Tor Klingberg Nov 10 '15 at 15:25
  • 1
    This approach has a problem - if response status is not 200, it doesn't print body. Any thoughts to resolve it? – Imaskar Aug 13 '18 at 09:24
  • 3
    See answer from Martin Wang - you need to add -q to actually see the output. – Ondřej Stašek Mar 03 '20 at 12:03
  • 3
    I want to output IP address from website so i just put wget -q -O - https://api.ipify.org and it's output it to the shell . – Salem F Aug 21 '20 at 18:34
  • In the more general case, shouldn't the URL be quoted (or otherwise)? In case it contains something the shell (say, on Linux or Windows) is very interested in, such as ampersands or semicolons. Sample: https://superuser.com/questions?tab=newest&page=542&pagesize=50. Used as is on Linux, this leads to output like "[1] 9663 [2] 9664" (9663 and 9664 are presumably process IDs) - the effective URL used by wget will be cut off - https://superuser.com/questions?tab=newest – Peter Mortensen Feb 01 '21 at 14:20
  • @PeterMortensen well yeah of course, you have to quote URLs with special characters :-) With simple urls though, noone will bother with quoting. This is the same with filenames. This is the basic shellwork though, isn't related to wget in any way. – Tomas Feb 01 '21 at 18:03
  • 1
    This redirects all output to /dev/null: wget -O - http://whatever.com/page.php > /dev/null

    You want the following (to redirect stderror only): wget -O - http://whatever.com/page.php 2> /dev/null

    – NeoH4x0r Jan 18 '22 at 21:48
247

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
  • 2,613
21
wget -qO /dev/null http://whatever.com/page.php
  • -q to make it quiet
  • -O /dev/null to ignore the page contents
unbeli
  • 334
13

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

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