Question

I've got a php script that uses curl and everything is fine. It runs via a cron job. I come back later and each time it runs a new file with the output has been saved.

How do I prevent these files from being created?

Was it helpful?

Solution

It's the cron daemon that makes that file. By default it saves the stdout into a file. Change the script to point its output to /dev/null instead:

/etc/crontab:

59 *    * * *   USER    curl localhost/script.php > /dev/null 2>&1

That would do the trick.

/Zyber

OTHER TIPS

If you're using wget to call your script in cron, you might need to set output to dev/null in the following manner:

59 * * * * wget -O - -q http://yourdomain.com/path/to/script.php

The -O specifies where output is written and the following - specifies dev/null. -q tells wget to run in quiet mode, meaning it won't write messages to stdout.

You can also suppress any output from cron, if it is creating the files, by changing the above line to the following:

59 * * * * wget -O - -q http://yourdomain.com/path/to/script.php > /dev/null 2>&1

The problem was since this is on a 'shared' hosting account, they claim it's not possible to send the cron results to /dev/null. Who knows, who cares. To fix the issue I've created a script that deletes the output files every day. Thanks for everyone's help.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top