Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
06-05-2012, 01:03 AM
|
#1
|
Member
Registered: Sep 2009
Posts: 117
Rep:
|
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?
|
|
|
06-05-2012, 04:04 AM
|
#2
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,992
|
why do you use -O /dev/null?
|
|
|
06-05-2012, 08:10 AM
|
#3
|
Moderator
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
|
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 for information on the options of wget.
|
|
|
06-05-2012, 08:33 AM
|
#4
|
Member
Registered: Mar 2004
Distribution: Debian
Posts: 285
Rep:
|
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]
|
|
|
06-05-2012, 03:59 PM
|
#5
|
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852
|
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.
|
|
|
06-06-2012, 12:27 AM
|
#6
|
Member
Registered: Sep 2009
Posts: 117
Original Poster
Rep:
|
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
|
|
|
06-06-2012, 05:43 AM
|
#7
|
Member
Registered: Feb 2009
Posts: 347
Rep:
|
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".
|
|
|
06-06-2012, 11:36 AM
|
#8
|
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852
|
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 03:49 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|