Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

Thanks

share|improve this question

marked as duplicate by jasonwryan, slm, Braiam, rahmu, casey Mar 19 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.

2 Answers 2

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

/var/log/cmdOutput_%Y_%m_%d_%H_%m.log
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.