I am running a cron job on my local server running Ubuntu 13.10 and want to create a log of the jobs performed. I can access the main log file, syslog, that shows if the cron job ran or had errors.
Here is my cronjob (runs every minute while I am testing, script is finished in under a few seconds)
* * * * * /usr/bin/php -f /home/[usr]/web/X/app/application.php &>> /home/[usr]/Maildir/geocode.log 2>&1 # JOB_ID_2
Inside my application.php file, I have several echos that output variables and results of queries performed:
echo "STARTING CRON @ ".date("m-d-Y H:i:s")."
";
echo count($properties) . " properties from query"."
";
If I run this file from the command line, the file executes correctly and the output is displayed. After looking up other questions about cron logs, I thought I needed to output the log file by the second half of the cron job:
>> /home/[usr]/Maildir/geocode.log 2>&1
Is this incorrect? How can I save and log the output from my php file? My file selects a number of object from a database and performs actions on them. I want to output the number initially worked on, number successfully completed, and any errors. Right now nothing is outputted, but I know the cron is running because the database it connects to is being updated correctly.
EDIT: I researched some more and thought 2>&1 would pass stderr into stdout because i wanted all of that info, but looks like this was preventing anything from being written. Using:
/usr/bin/php -f /home/[usr]/web/X/app/application.php >> /home/[usr]/Maildir/geocode.log
Adds all of the output I was expecting into the log file, but I am unsure what will happen with errors because it is running fine now. I will leave this open in case anyone else wants to add anything about creating a log file and if 2>&1 should ever be used in a situation where we want to keep both stderr and stdout.