Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

This question already has an answer here:

I have some cron jobs set up to run, some of them each minute. I know I can log them to text files by simply putting php /path/to/file.php > /var/logs/something.txt but can I do this every minute? The nature of the log's output means that the log file will be very small, but I don't know how to log each minute's output to a separate file.


share|improve this question

marked as duplicate by jasonwryan, slm, Braiam, rahmu, casey Mar 19 '14 at 15:19

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

up vote 1 down vote accepted

You can pipe the output to cronolog for log file time handling. For documentation see Cronolog Usage and download Cronolog at Sourceforge

General example

command "|/path/to/cronolog [OPTIONS] logfile-spec"

where logfile-spec for you could be

share|improve this answer

As pointed out by jasonwryan here, you could try something like this:

* * * * * bash -lc "php /path/to/file.php" > "/var/logs/something_$(date +\%Y\%m\%d-\%h\%m).txt" 2>&1

The bash -lc is here to be sure you script will be executed with the same environment as you are use to (in particular $PATH).

share|improve this answer

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