I have a cron set to run every minute
* * * * * /usr/php /my/location/script.php
Now, I use time function to measure script execution time. So, running
console$ time /usr/php /my/location/script.php
outputs
real 0m0.000s
user 0m0.000s
sys 0m0.000s
But it doesn't work with cron like this:
* * * * * time /usr/php /my/location/script.php 2>&1 >> my_log_file
neither does it work on command line
console$ time /usr/php /my/location/script.php >> my_log_file
In both of the above examples, the time function actually calculates the time taken to write to my_log_file, instead of writing its output to the log file. Adding code in the script and recording STD OUTPUT is NOT AN OPTION.
What about:
How about the in-built cron daemon feature?
Check your cron daemon's man page. Many have a "-L" argument to specify a log level. Eg on Ubuntu (ie, Debian):
The problem is using the
time
shell builtin vs. thetime
binary. Using the builtin it doesn't work, even with the proper redirection:Using the binary works:
With GNU time you can use the
-o
and-a
options instead of shell redirection:I would probably try putting
Into a script and then calling that script from your cron job.
As an aside, is your php binary really in /usr? Or /usr/bin?
it seems
time
is bash builtin (at least on my system). Following works for me:/bin/bash -c 'time ls' > out.std 2> out.err
. Output oftime
would be in stderr (out.err file).