Search code examples
linuxapachecroncron-task

How to output both the cron log and the script output to the same fiile?


I use a wget cron, my syntax is like this:

*/5 * * * * wget http://www.example.com/process_queue >>/home/logs/queue_folder/`date +\%Y-\%m-\%d_\%H:\%M:\%S`-cron.log 2>&1

I've read on another page that the ">>" before the file path it's suppose to write both the log and the output to the specified file. But it has no effect. The log is written to the file but the script output goes in a "process_queue.xx" file in the root folder of my hosting account.

How can I get the output to append to that file or to point to another folder?

Thanks!


Solution

  • You need to tell wget to write to stdout with "-O" , >> will just overwrite your file, its not needed here.

    wget http://www.example.com/process_queue -O > /home/logs/queue_folder/date +\%Y-\%m-\%d_\%H:\%M:\%S-cron.log 2>&1