cron and wget

Started by sanjana, Aug 03, 2022, 01:46 AM

Previous topic - Next topic

sanjanaTopic starter

For all cron jobs I use following command:
wget -q http://mysite.com/script.php >/dev/null
But then, at each start, a file with the cron operation result is created at the ftp root. How to make that it is not created? Linux users, please help!
  •  

musorhik

Should be like that:
wget -q http://mysite.com/script.php -O - >/dev/null 2>&1
Option -q = quiet - removes output of service info about downloading.
option -O = output, allows you to save what is downloaded to a file with the specified name. In such case, standard output is used as the file, which is indicated simply by a hyphen - .
Further, redirecting this result to a special file > /dev/null - the so-called "black hole", that is, dumping the result to nowhere. If you give a command without this, then it will spit out the contents of what he pumps out directly into the console. Further, the redirection of I / O streams - the stream with descriptor 2 is stderr - any possible errors, we redirect to the stream with descriptor 1, which is standard output, that is, to the same place as the result of the wget itself - to / dev / null

my version of the command will work "silently", never write anything or create any files.

But this is not really the best way to run php scripts. They can be launched directly from the console using php-cli, and instead of wget, write something like this command in cron:
php /var/www/mysite.com/script.php > /dev/null 2>&1
  •