LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 08-25-2008, 06:20 AM   #1
okhalid
LQ Newbie
 
Registered: Aug 2008
Posts: 3

Rep: Reputation: 0
How to redirect the output to a logfile?


Hi,

I have to redirect the output of a time function of a command which also redirects also its out output to a log file:

time athena.py jobOptions.pythia.py | tee athena_gen.out 2>&1

Output of athena.py is already going to athena_gen.out but I would like to redirect the output of time to a file too..

Thanks,
Omer
 
Old 08-25-2008, 06:27 AM   #2
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655
Just add >file at the end. It would be better to use tee to write to the file and use >>logfile, so that the logfile isn't zeroed out each time.

Last edited by jschiwal; 08-25-2008 at 06:29 AM.
 
Old 08-25-2008, 08:22 AM   #3
okhalid
LQ Newbie
 
Registered: Aug 2008
Posts: 3

Original Poster
Rep: Reputation: 0
Putting an additional > is not enough as it copies the same output to both logfiles :-(

I think there would be some other trick to do that :-)

Any ideas?
 
Old 08-25-2008, 08:32 AM   #4
raskin
Senior Member
 
Registered: Sep 2005
Location: Russia
Distribution: NixOS (http://nixos.org)
Posts: 1,893

Rep: Reputation: 68
I don't see any sense in "2>&1" in the tee invocation; if you run
Code:
time athena.py jobOptions.pythia.py 2>&1 | tee athena_gen.out
, it should work.
 
Old 08-25-2008, 08:40 AM   #5
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
If you want the output of time redirected to another file, be sure to use the actual GNU time command. Since Bash 2.0 time is a reserved shell keyword, having a slightly different behaviour in respect of the time command. You can verify this by
Code:
$ type time
time is a shell keyword
To actually use the GNU time (if installed on your system) you have to specify its full path. Then you can use its options to format the output and to redirect it to a file, for example:
Code:
/usr/bin/time -p -o time.log athena.py jobOptions.pythia.py 2>&1 | tee athena_gen.out
The -p option gives the portable output format, that is the same as that from the shell keyword.
 
Old 08-25-2008, 09:59 AM   #6
okhalid
LQ Newbie
 
Registered: Aug 2008
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by colucix View Post
If you want the output of time redirected to another file, be sure to use the actual GNU time command. Since Bash 2.0 time is a reserved shell keyword, having a slightly different behaviour in respect of the time command. You can verify this by
Code:
$ type time
time is a shell keyword
To actually use the GNU time (if installed on your system) you have to specify its full path. Then you can use its options to format the output and to redirect it to a file, for example:
Code:
/usr/bin/time -p -o time.log athena.py jobOptions.pythia.py 2>&1 | tee athena_gen.out
The -p option gives the portable output format, that is the same as that from the shell keyword.
This is what I wanted...Thanks :-)
 
  


Reply

Tags
logfile, output, redirect


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to redirect the output of exec command output in perl? sudhap85 Linux - Newbie 3 08-28-2009 04:35 PM
Shell scripting: Print output to logfile, error to logfile & screen stefanlasiewski Programming 18 05-22-2008 01:47 PM
Perl Dumping output into logfile. misconfiguration Programming 6 08-10-2007 03:19 AM
Redirect output jimwelc Linux - Newbie 3 05-11-2006 12:10 PM
Can I redirect script output to a file without ">> $LOGFILE" at the end of each line davee Linux - General 1 12-19-2003 06:01 AM


All times are GMT -5. The time now is 09:05 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration