Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using wget in a crontab to run a PHP script

I set up a cron job on my Ubuntu server. Basically, I just want this job to call a php page on an other server. This php page will then clean up some stuff in a database. So I tought it was a good idea to call this page with wget and then send the result to /dev/null because I don't care about the output of this page at all, I just want it to do its database cleaning job. So here is my crontab:

0 0 * * * /usr/bin/wget -q --post-data 'pass=mypassword' http://www.mywebsite.com/myscript.php > /dev/null 2>&1

(I post a password to make sure no one could run the script but me). It works like a charm except that wget writes each time an empty page in my user directory: the result of downloading the php page.

I don't understand why the result isn't send to /dev/null ? Any idea about the problem here? Thanks you very much!

like image 398
JuCachalot Avatar asked Jul 13 '26 21:07

JuCachalot


2 Answers

wget's output to STDOUT is it trying to make a connection, showing progress, etc.

If you don't want it to store the saved file, use the -O file parameter:

/usr/bin/wget -q --post-data -O /dev/null 'pass=mypassword' http://www.mywebsite.com/myscript.php > /dev/null 2>&1

Checkout the wget manpage. You'll also find the -q option for completely disabling output to STDOUT (but offcourse, redirecting the output as you do works too).

like image 186
Konerak Avatar answered Jul 15 '26 16:07

Konerak


wget -O /dev/null ....

should do the trick

like image 26
Gryphius Avatar answered Jul 15 '26 14:07

Gryphius



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!