1

I am trying to benchmark a single request agains a webserver, and am having a problem doing so, specifically, I am having an issue redirecting the output of the time command.

If i simply run

time curl "http://www.google.com"

my result is the full body response, followed by the printout from the time command.

If i run it with redirection

time curl "http://www.google.com" 1> out.log 2> err.log

In out.log I still see the body of the response, and in err.log I see the output from the curl command

The problem however is that the output from the time command is still printing to the terminal

[501] ~ > time curl "http://www.google.com" 1> out.log 2> err.log

real    0m0.092s
user    0m0.004s
sys     0m0.004s

[502] ~ > cat err.log
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 19093    0 19093    0     0   225k      0 --:--:-- --:--:-- --:--:--  227k

To what buffer does time output, and how canI get this into a file? From my understanding, it should have been piped into err.log.

2
  • 1
    Here is a great way to achieve what you want without the use of time: stackoverflow.com/questions/18215389/…
    – arana
    Apr 14, 2016 at 15:26
  • ooohhhh, I like that :) and will definitely switch to that as it gives me a lot of the information that i actually need. Still doesn't answer the question though :)
    – Matt Clark
    Apr 14, 2016 at 15:30

2 Answers 2

2

You can try with { time curl -s https://www.google.com ; } > body.txt 2> time.txt

1

If you don't use the bash-internal version but the GNU tool (e.g. /usr/bin/time), you have the -o option as explained by man time:

/usr/bin/time -po outfile.txt curl "http://www.google.com"

will write the time to outfile.txt.

GNU time has many options to format the output, see the man page for details.

3
  • sure, I can do this, but why will the redirects not work, even &> still results in output to the shell.
    – Matt Clark
    Apr 14, 2016 at 15:20
  • Nope, it does not. I just edited my question, showing the output of err.log.
    – Matt Clark
    Apr 14, 2016 at 15:24
  • Correct, I misinterpreted some fragments in the file. Anyway, my guess is that this is due to the fact that this bash-internal isn't really affected by stream redirections, as no process is executed. See Kelzier's variant to avoid this.
    – Sven
    Apr 14, 2016 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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