Home Web Hosting How to Prevent a Cron from Creating Empty Files in Root

How to Prevent a Cron from Creating Empty Files in Root

by rigotechnology

This simple guide will show you how to prevent a cron job from filling the root directory of your hosting account with empty files. From the fact that your cron job command you have is currently filling your root directory with empty files, it probably looks similar to this:

wget -q http://www.yourdomain.com/somescript.php

Natively, when wget gets called, it visits the location and retrieves/writes a results file from the web page it is called to. Even if the page that is being called doesn’t have any results, the wget command will still create a file. Since there was nothing to retrieve, the result is empty.

There is a simple fix that will prevent the blank file from being created. By simply adding -O option to your wget command, you can specify a location to download the results to. When you specify wget to write the file to location /dev/null, the file will be discarded. Your new cron job command should look similar to this:

wget -q -O /dev/null http://www.yourdomain.com/somescript.php

The reason this works is that you are telling wget to visit your webpage to get results, -q to quiet the response, and -O to write the results files in the location /dev/null. /dev/null is a null device, which discards any information that is written into it, therefore your results file will be discarded.

That’s it! By adding this one simple option, you won’t have blank files constantly filling up your root! Goodbye pesky empty files!

Bonus tip! If you have a cronjob such as the following

* * * * * /bin/sh /something.sh

You can add “> /dev/null 2>&1” to the end of it to produce the same effect. Here is an example:

* * * * * /bin/sh /something.sh > /dev/null 2>&1


You may also like