LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   time + wget = file (https://www.linuxquestions.org/questions/linux-newbie-8/time-wget-%3D-file-948562/)

L1nuxn00b703 06-05-2012 12:03 AM

time + wget = file
 
Hi all,
I have the following command I'm trying to capture to a file but I'm unable to:
Code:

time wget -O /dev/null www.example.com
Is there a way to capture the time and wget output to a file?

pan64 06-05-2012 03:04 AM

why do you use -O /dev/null?

TobiSGD 06-05-2012 07:10 AM

Actually you are downloading a file, but with the -O /dev/null parameter you are directly sending it into non-existence. Have a look at
Code:

man wget
for information on the options of wget.

rizzy 06-05-2012 07:33 AM

Code:

wget smxi.org/smxi.zip -o test.txt && cat test.txt
Code:

--2012-06-05 13:30:36--  http://smxi.org/smxi.zip
Resolving smxi.org (smxi.org)... 209.197.72.47
Connecting to smxi.org (smxi.org)|209.197.72.47|:80... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: http://smxi.org/sm/smxi.zip [following]
--2012-06-05 13:30:37--  http://smxi.org/sm/smxi.zip
Reusing existing connection to smxi.org:80.
HTTP request sent, awaiting response... 200 OK
Length: 166561 (163K) [application/zip]
Saving to: `smxi.zip'

    0K .......... .......... .......... .......... .......... 30%  120K 1s
    50K .......... .......... .......... .......... .......... 61%  268K 0s
  100K .......... .......... .......... .......... .......... 92%  300K 0s
  150K .......... ..                                        100%  448K=0.8s

2012-06-05 13:30:38 (203 KB/s) - `smxi.zip' saved [166561/166561]


David the H. 06-05-2012 02:59 PM

time and the base output of wget both print to stderr. If you want to capture the printed output of the exact command above, use this:

Code:

time { wget -O /dev/null www.example.com ;} 2> outfile.txt
http://wiki.bash-hackers.org/syntax/redirection


The {...;} brackets are for command grouping. Maybe not necessary in this case, but I think it's better to always clearly frame whatever the time command is supposed to measure. It also allows you to set up separate redirections for both the inside and outside commands, if you want. You can also use (..) subshell grouping.

L1nuxn00b703 06-05-2012 11:27 PM

Ahhh thx guyz!!!

@David the H. I tried your suggestion but it doesn't log the time portion:

Code:

# time { wget -O /dev/null www.example.com ;} 2> outputfile

real    0m0.283s
user    0m0.001s
sys    0m0.004s

# more outfile.txt
--2012-06-06 00:26:21--  http://www.example.com/
Resolving www.example.com... 192.0.43.10, 2001:500:88:200::10
Connecting to www.example.com|192.0.43.10|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://www.iana.org/domains/example/ [following]
--2012-06-06 00:26:21--  http://www.iana.org/domains/example/
Resolving www.iana.org... 192.0.32.8, 2620:0:2d0:200::8
Connecting to www.iana.org|192.0.32.8|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: `/dev/null'

    0K ..                                                      157M=0s

2012-06-06 00:26:21 (157 MB/s) - `/dev/null' saved [2966]

I'm trying to add both time and the stderr of wget to a file

bsat 06-06-2012 04:43 AM

The time command also has a -o option with which you can print the output to a file.
But don't use the bash inbuilt time as this does not have the logging option, instead use "/usr/bin/time".

David the H. 06-06-2012 10:36 AM

Hmm, that's odd. I could've sworn it was working when I tested it yesterday, but you're right. For some reason I can't quite fathom the curly-bracket command grouping isn't saving them both. The redirection is only being applied to the grouping.

But it does save them both when I use a subshell instead.

Code:

time ( wget -O /dev/null www.example.com ) 2> outputfile


All times are GMT -5. The time now is 08:57 AM.