[clug] Redirect time command output to file

Hal hal.ashburner at gmail.com
Wed May 26 21:24:20 MDT 2010


Hi CLUG,
I'm running a cron job to do some testing for me and want to record some 
pretty basic performance numbers. The time command looks like the thing 
I want.

Now I've been bitten because "man time" is actually full of lies. time 
appears to be a shell builtin command that bares basically zero 
resemblance to the information in man time.
Specifically there are no -a or -o options to write output to a file.

$ time echo "foo" 2>&1 >>output.log
happily appends "foo" to output.log but still spits out the time output 
on the terminal. This suggests to me there's a magic third output file 
handle. In addition to stdout & stderr there is stdshell or something 
this? Or am I missing something concerning redirection here?

$help time
has no useful information about this at all.

Google is increasingly useless for this kind of thing as the more you 
refine your query the more google will helpfully drop the keywords that 
you need to filter out all the stuff that has nothing to do with what 
you're asking. (We need a google.com/exactly_what_I_asked_for_dammit 
specialist front end rather than pacman, I reckon but I digress. Maybe 
there is one somewhere that wraps any bare keywords in quotes and 
prepends a + sign for all I know.)

Ok Invoke the time binary explicitly

/usr/bin/time --append -o logfile.log /path/to/timed/command 2>&1 >> 
logfile.log
Seems to work.

Anyone got any better thoughts on how to save time information for a 
long running command to log file?
Hmm, so what is the excuse for reimplementing it in the shell with magic 
file handles? Why don't both "$ man time"and "$ help time" mention the 
other given it is going to cause issues?

Are there better ways of roughly profiling python database code to give 
you a heads up if you've done something that kills performance?

Cheers all,
Hal

PS "Harsh realities of CLUG" as a topic made me laugh. Harsh realities 
of warm and fluffy baby ducklings. IMHO CLUG is nice, kind people.


More information about the linux mailing list