LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 06-05-2012, 01:03 AM   #1
L1nuxn00b703
Member
 
Registered: Sep 2009
Posts: 117

Rep: Reputation: 15
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?
 
Old 06-05-2012, 04:04 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,992

Rep: Reputation: 7624Reputation: 7624Reputation: 7624Reputation: 7624Reputation: 7624Reputation: 7624Reputation: 7624Reputation: 7624Reputation: 7624Reputation: 7624Reputation: 7624
why do you use -O /dev/null?
 
Old 06-05-2012, 08:10 AM   #3
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
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.
 
Old 06-05-2012, 08:33 AM   #4
rizzy
Member
 
Registered: Mar 2004
Distribution: Debian
Posts: 285

Rep: Reputation: 69
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]
 
Old 06-05-2012, 03:59 PM   #5
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
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.
 
Old 06-06-2012, 12:27 AM   #6
L1nuxn00b703
Member
 
Registered: Sep 2009
Posts: 117

Original Poster
Rep: Reputation: 15
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
 
Old 06-06-2012, 05:43 AM   #7
bsat
Member
 
Registered: Feb 2009
Posts: 347

Rep: Reputation: 72
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".
 
Old 06-06-2012, 11:36 AM   #8
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Defining a time limit for wget rnturn Linux - Software 2 03-25-2012 09:49 PM
How to get time of WGET on success or print message on failure smrutimandal Programming 5 09-09-2011 01:02 PM
saving a page using wget+command -O not found+each time i'v to break manually Kakarot_Rathish Programming 5 04-13-2010 05:06 AM
First time using wget NightSky Linux - Software 10 10-12-2009 06:30 PM
how to make wget user sytem time muxman Linux - Software 5 10-24-2006 02:15 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration