LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   How to redirect the output to a logfile? (https://www.linuxquestions.org/questions/linux-general-1/how-to-redirect-the-output-to-a-logfile-665200/)

okhalid 08-25-2008 05:20 AM

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

jschiwal 08-25-2008 05:27 AM

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.

okhalid 08-25-2008 07:22 AM

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?

raskin 08-25-2008 07:32 AM

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.

colucix 08-25-2008 07:40 AM

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.

okhalid 08-25-2008 08:59 AM

Quote:

Originally Posted by colucix (Post 3258930)
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 :-)


All times are GMT -5. The time now is 09:03 AM.