Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

2 Answers 2

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) –  Ultra 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:

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
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.