Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Why my cron */1 * * * * /usr/bin/php /var/www/query/query.php &> /root/querylog.log saves query.php output in the /root/ folder?

(this script shall save *.txt at its location)

It should do so at /var/www

Folder owner of var/www/query/ is web-data.

Running it on Debian Squeeze 6.0

share|improve this question
Out of curiosity what is the output of query.php? Maybe you should specify correct path of its output inside your php code? – Sandro Dzneladze Jul 19 '12 at 7:32
What user is the cron running as? – danio Sep 12 '12 at 9:05

The querylog.log file is saved in the /root directory because that's exactly where you have specified it should be saved.

If you want to change its location, just edit the path to your desired location, e.g. /var/www/querylog.log.

share|improve this answer
saves query.php output is 2 *.txt files. When fired at my local machine they are created at the same dir as the query.php. But cron saves 'em there, where log is saved - why? (output and log fire are 2 separate things btw) – Szymon Toda Jul 16 '12 at 8:49
I think he is not talking about .log file but rather output of query.php, log goes in root as he wants it to do. – Sandro Dzneladze Jul 19 '12 at 7:52

This happens because the cron job it is run as root user, so it is executed at the root user's $HOME, i.e. /root.

If you want the cron job to run in another location, so that the output is generated there, you should move there first eg writting a script which does everything and runnig it from cron:


cd /var/www
/var/www/query/query.php &> /root/querylog.log

And the cron line becomes

*/1 * * * * /bin/bash /path/to/script/my_query.bash
share|improve this answer
I don't understand the down votes for this answer: it seems to be saying exactly what happens (query.php saves output to directory it is run from, cron runs it as root, so script runs in .roo – danio Sep 12 '12 at 9:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .