LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 02-18-2013, 06:12 PM   #1
sanaz
Member
 
Registered: Aug 2012
Posts: 76

Rep: Reputation: Disabled
Redirecting exact output to a file


Hi all, I'm trying to redirect output of a script to a file. But output in file differs from what has been shown on screen.
Is there any way to redirect exact screen output to a file?

As the hardest part of my problem, I'm using wget to download 999,999,999 files and I want to have the output in a file(then I'm processing these data), but each percentage of download which is completed is shown in file for several time, I want the exact output of screen to a file.
 
Old 02-18-2013, 06:41 PM   #2
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 414Reputation: 414Reputation: 414Reputation: 414Reputation: 414
Make sure you are redirecting stderr and stdout.


http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-3.html
 
Old 02-18-2013, 06:51 PM   #3
sanaz
Member
 
Registered: Aug 2012
Posts: 76

Original Poster
Rep: Reputation: Disabled
using
Code:
 wget http://speedtest.wdc01.softlayer.com/downloads/test500.zip > a.txt
and
Code:
wget http://speedtest.wdc01.softlayer.com/downloads/test500.zip 1> a.txt
does not write anything in a.txt
and
Code:
wget http://speedtest.wdc01.softlayer.com/downloads/test500.zip 2> a.txt
is not the same as screen output.

Any help?
 
Old 02-18-2013, 06:55 PM   #4
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 414Reputation: 414Reputation: 414Reputation: 414Reputation: 414
Code:
wget http://speedtest.wdc01.softlayer.com/downloads/test500.zip &> ./output.txt

You must use the &> to redirect both stdout and stderr. You should always check the man page too as most have redirect options built in.

-o ./output.txt would work just fine for wget.
 
Old 02-18-2013, 06:58 PM   #5
sanaz
Member
 
Registered: Aug 2012
Posts: 76

Original Poster
Rep: Reputation: Disabled
Thanks for your answer, but still the same problem exists with both of them.
 
Old 02-18-2013, 07:03 PM   #6
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 414Reputation: 414Reputation: 414Reputation: 414Reputation: 414
Then you are not seeing either stdout or stderr you either need to be more specific or what you are seeing cannot be redirected(which should be impossible but some ncurses and other things could be a factor).
 
Old 02-18-2013, 07:29 PM   #7
sanaz
Member
 
Registered: Aug 2012
Posts: 76

Original Poster
Rep: Reputation: Disabled
For time it differs.

Also for wget, here is the result:
Code:
$ wget http://speedtest.wdc01.softlayer.com/downloads/test500.zip
--2013-02-18 19:26:15--  http://speedtest.wdc01.softlayer.com/downloads/test500.zip
Resolving speedtest.wdc01.softlayer.com... 208.43.102.250
Connecting to speedtest.wdc01.softlayer.com|208.43.102.250|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 524288000 (500M) [application/zip]
Saving to: “test500.zip”

100%[========================================================================================================================================>] 524,288,000 43.4M/s   in 9.5s    

2013-02-18 19:26:30 (52.5 MB/s) - “test500.zip” saved [524288000/524288000]

and

Code:
$ wget http://speedtest.wdc01.softlayer.com/downloads/test500.zip &> ./output.txt
$ less output.txt 

--2013-02-18 19:28:12--  http://speedtest.wdc01.softlayer.com/downloads/test500.zip
Resolving speedtest.wdc01.softlayer.com... 208.43.102.250
Connecting to speedtest.wdc01.softlayer.com|208.43.102.250|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 524288000 (500M) [application/zip]
Saving to: “test500.zip”

     0K .......... .......... .......... .......... ..........  0% 2.01M 4m8s
    50K .......... .......... .......... .......... ..........  0% 3.85M 3m9s
   100K .......... .......... .......... .......... ..........  0% 3.87M 2m49s
   150K .......... .......... .......... .......... ..........  0% 3.95M 2m38s
   200K .......... .......... .......... .......... ..........  0% 81.5M 2m8s
   250K .......... .......... .......... .......... ..........  0% 3.97M 2m8s
   300K .......... .......... .......... .......... ..........  0% 87.4M 1m50s
   350K .......... .......... .......... .......... ..........  0% 4.09M 1m52s
   400K .......... .......... .......... .......... ..........  0% 65.0M 1m40s
   450K .......... .......... .......... .......... ..........  0% 4.21M 1m42s
   500K .......... .......... .......... .......... ..........  0% 75.1M 93s
   550K .......... .......... .......... .......... ..........  0% 83.4M 86s
   600K .......... .......... .......... .......... ..........  0% 72.0M 80s
   650K .......... .......... .......... .......... ..........  0% 4.53M 82s
   700K .......... .......... .......... .......... ..........  0% 62.7M 77s
   750K .......... .......... .......... .......... ..........  0% 77.8M 73s
   800K .......... .......... .......... .......... ..........  0% 4.63M 75s
   850K .......... .......... .......... .......... ..........  0% 77.3M 71s
   900K .......... .......... .......... .......... ..........  0% 72.3M 68s
   950K .......... .......... .......... .......... ..........  0% 74.3M 65s
  1000K .......... .......... .......... .......... ..........  0% 81.4M 62s
  1050K .......... .......... .......... .......... ..........  0% 75.9M 59s
  1100K .......... .......... .......... .......... ..........  0% 74.7M 57s
 
Old 02-18-2013, 07:31 PM   #8
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 414Reputation: 414Reputation: 414Reputation: 414Reputation: 414
So your only issue is the pretty bar that it draws out showing your download progress? You will have to deal with that. Your redirection is working as intended.
 
Old 02-18-2013, 07:33 PM   #9
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 414Reputation: 414Reputation: 414Reputation: 414Reputation: 414
If you are also concerned that your download times are slightly different, that is the way the internet works. Your speed is never going to be 100% the same, however it should stay within a relative range.
 
Old 02-19-2013, 02:55 AM   #10
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
There is a difference between being connected to a terminal and sending output to a file, as the man page of wget states:
Quote:
The "bar" indicator is used by default. It draws an ASCII progress bar graphics (a.k.a
"thermometer" display) indicating the status of retrieval. If the output is not a TTY, the "dot"
will be used by default.
but you can force wget to display the "bar" indicator by means of:
Code:
wget --progress=bar:force -o output.txt http://speedtest.wdc01.softlayer.com/downloads/test500.zip
Hope this helps.
 
Old 02-19-2013, 12:33 PM   #11
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,599

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
Quote:
Originally Posted by sanaz View Post
Hi all, I'm trying to redirect output of a script to a file. But output in file differs from what has been shown on screen.
Is there any way to redirect exact screen output to a file?

As the hardest part of my problem, I'm using wget to download 999,999,999 files and I want to have the output in a file(then I'm processing these data), but each percentage of download which is completed is shown in file for several time, I want the exact output of screen to a file.
Try the "script" utility. It will record everything sent to the screen, including any escape sequences for handling color, screen positions...

It even records the <cr><lf> of the physical I/O for the end of lines.
 
Old 02-19-2013, 11:55 PM   #12
smbhandary
LQ Newbie
 
Registered: Jan 2013
Distribution: RHEL and AIX ( sort of )
Posts: 18

Rep: Reputation: Disabled
based on my understanding of your problem statement : content of log file differs from console output.

Try tee

<command> | tee /tmp/log -- to create /tmp/log or null existing file /tmp/log and write to it.
<command> | tee -a /tmp.log -- to append output to file /tmp/log

Last edited by smbhandary; 02-20-2013 at 12:05 AM.
 
Old 02-20-2013, 06:59 AM   #13
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,599

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
Tee works sometimes - It depends on whether the program tests for a real terminal or not and generates different output.

Tee is designed for use in a pipe (as shown), but not with some other applications (such as an editor).

Even "ls" works differently - if the output is attached to a terminal then it will use a multi-column output with color highlighting. If it is attached to a pipe, then it outputs a single column, with no escape sequences for color highlighting.
 
Old 02-20-2013, 07:21 AM   #14
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 979
Blog Entries: 2

Rep: Reputation: 235Reputation: 235Reputation: 235
wget http://speedtest.wdc01.softlayer.com...ds/test500.zip > ./output.txt 2>&1
 
  


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
Redirecting one output to another file amjadask Linux - Server 3 02-14-2011 12:21 PM
Redirecting output to a compressed file rrosnowski Linux - Software 3 06-13-2007 08:51 AM
Redirecting socket output to a file elmafiacs Programming 1 10-15-2005 06:18 AM
Redirecting colsole output to file. danimallv Linux - General 4 07-05-2005 03:44 PM
redirecting output of compile to a file halfcan Linux - Hardware 1 02-05-2005 11:01 PM


All times are GMT -5. The time now is 06:01 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration