335

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?

7 Answers7

335

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
  • 8,080
265

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,793
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/
0

I could never get this to work just right with wget, but if you have python and the requests library on your system, this might work better for you:

python -c "import requests;print(requests.get('http://whatever.com/page.php').text)"
Peter
  • 171
0

I use this approach to get the output of the request:

wget http://localhost:8000/live -O test && cat test && echo "\n" && rm test

One disadvantage is however that you need write rights. So you might use the tmp folder for writing the temporary result.