1

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

2
  • Out of curiosity what is the output of query.php? Maybe you should specify correct path of its output inside your php code?
    – user98645
    Jul 19, 2012 at 7:32
  • What user is the cron running as?
    – danio
    Sep 12, 2012 at 9:05

2 Answers 2

3

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.

2
  • 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) Jul 16, 2012 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.
    – user98645
    Jul 19, 2012 at 7:52
1

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:

my_query.bash

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
1
  • 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, 2012 at 9:04

You must log in to answer this question.

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