Using Time Command With Command That Redirects Output.

Using Time Command With Command That Redirects Output.

Post by Gazz » Sat, 18 Jun 2005 11:40:08



Hi,

When I did this:

time ls foo 2> /dev/null

,where 'foo' didn't exist, I didn't get the result of the 'time' command.
Both the standard errors of 'time' _and_ 'ls' were sent to '/dev/null'.
How do I get just the standard error of the 'ls' command to go to standard
error?  BTW, this:

time ls foo

,again where 'foo' doesn't exist, gives 'no such file' error messages on
standard output for _both_ the 'time' _and_ 'ls' commands.

Yours,
Gary Hayward.

 
 
 

Using Time Command With Command That Redirects Output.

Post by Alan Conno » Sat, 18 Jun 2005 13:02:51


On comp.unix.shell, in


> Hi,

> When I did this:

> time ls foo 2> /dev/null

> ,where 'foo' didn't exist, I didn't get the result of the
> 'time' command.  Both the standard errors of 'time' _and_ 'ls'
> were sent to '/dev/null'.  How do I get just the standard error
> of the 'ls' command to go to standard error?  BTW, this:

> time ls foo

> ,again where 'foo' doesn't exist, gives 'no such file' error
> messages on standard output for _both_ the 'time' _and_ 'ls'
> commands.

> Yours, Gary Hayward.

What shell are you using? Both of those work fine on bash.

AC

 
 
 

Using Time Command With Command That Redirects Output.

Post by Gazz » Sun, 19 Jun 2005 01:10:15



> On comp.unix.shell, in

>> Hi,

>> When I did this:

>> time ls foo 2> /dev/null

>> ,where 'foo' didn't exist, I didn't get the result of the
>> 'time' command.  Both the standard errors of 'time' _and_ 'ls'
>> were sent to '/dev/null'.  How do I get just the standard error
>> of the 'ls' command to go to standard error?  BTW, this:

>> time ls foo

>> ,again where 'foo' doesn't exist, gives 'no such file' error
>> messages on standard output for _both_ the 'time' _and_ 'ls'
>> commands.

>> Yours, Gary Hayward.

> What shell are you using? Both of those work fine on bash.

> AC

Hi,

I'm using BASH, 'bash --version' gives the following:  'GNU bash, version
2.05b.0(1)-release (i586-mandrake-linux-gnu)'.

Yours,
Gary Hayward.

 
 
 

Using Time Command With Command That Redirects Output.

Post by Gazz » Sun, 19 Jun 2005 01:55:16



> On comp.unix.shell, in

>> Hi,

>> When I did this:

>> time ls foo 2> /dev/null

>> ,where 'foo' didn't exist, I didn't get the result of the
>> 'time' command.  Both the standard errors of 'time' _and_ 'ls'
>> were sent to '/dev/null'.  How do I get just the standard error
>> of the 'ls' command to go to standard error?  BTW, this:

>> time ls foo

>> ,again where 'foo' doesn't exist, gives 'no such file' error
>> messages on standard output for _both_ the 'time' _and_ 'ls'
>> commands.

>> Yours, Gary Hayward.

> What shell are you using? Both of those work fine on bash.

> AC

Hi,

Here are the results of my experiments (what I'm trying to achieve is output
comprising of _just_ the time it takes the 'ls foo' command to work (using
the 'time' command), whether of not 'foo' exists; I don't want any error
messages at all).  The error messages of 'time' can be avoided with the
'--quiet' option BTW, but it seems impossible to get rid of the error
message from 'ls' if the file ('foo', in this case) does not exist:

input:
time ls foo

output (if foo exists):
foo
0.00user 0.00system 0:00.00elapsed 83%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+305minor)pagefaults 0swaps

output (if foo does not exist):
ls: foo: No such file or directory
Command exited with non-zero status 1
0.00user 0.00system 0:00.00elapsed 80%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+242minor)pagefaults 0swaps

input:
time ls foo > /dev/null

output (if foo exists):
0.00user 0.00system 0:00.00elapsed 83%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+304minor)pagefaults 0swaps

output (if foo does not exist):
ls: foo: No such file or directory
Command exited with non-zero status 1
0.00user 0.00system 0:00.00elapsed 60%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+242minor)pagefaults 0swaps

input:
time ls foo 2> /dev/null

output (if foo exists):
foo

output (if foo does not exist):
[nothing]

input:
time ls foo > /dev/null 2>&1

output (if foo exists):
[nothing]

output (if foo does not exist):
[nothing]

I tried piping through grep:

input:
time --quiet ls foo | grep -v ls

output (if foo does not exist):
ls: foo: No such file or directory
0.00user 0.00system 0:00.00elapsed 75%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+242minor)pagefaults 0swaps

In fact, 'grep' doesn't work at all (try it without the '-v' option).

I've tried storing the output of the command in a variable:

input:
tm=$( time --quiet ls foo )

output (if foo exists):
0.00user 0.00system 0:00.00elapsed 80%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+304minor)pagefaults 0swaps

Yes, despite saying I wanted the output just put in variable 'tm', I got
output (and, 'no'; sticking ouput redirection in anywhere in the last
command doesn't work, whether 'foo' exists or not)!  And when I then did
this:

input:
echo $tm

output:
[blank line]

The only way I managed to do what I want is to create my own BASH-scripted
'ls' command (called 'myqls', meaning 'my quiet ls') in /usr/local/bin as
follows:

#!/bin/bash

ls $1 2> /dev/null

then use the time command like this:

input:
time --quiet myqls foo > /dev/null

output (if foo exists):
0.00user 0.00system 0:00.01elapsed 91%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+673minor)pagefaults 0swaps

output (if foo does not exist):
0.00user 0.00system 0:00.01elapsed 91%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+611minor)pagefaults 0swaps

The only thing is that using 'myqls' adds a small amount of time to the
result of 'time'.  Maybe I'll need to include 'time' in my 'myqls' script
-- oh no!  Is my solution the only one?

Yours,
Gary Hayward.

 
 
 

Using Time Command With Command That Redirects Output.

Post by John DuBo » Sun, 19 Jun 2005 02:20:44



>When I did this:

>time ls foo 2> /dev/null

>,where 'foo' didn't exist, I didn't get the result of the 'time' command.
>Both the standard errors of 'time' _and_ 'ls' were sent to '/dev/null'.
>How do I get just the standard error of the 'ls' command to go to standard
>error?
> I'm using BASH, 'bash --version' gives the following:  'GNU bash, version
> 2.05b.0(1)-release (i586-mandrake-linux-gnu)'.

Sounds like you're using an external time command instead of the bash time
builtin - maybe it's aliased?  If so:

time bash -c 'ls foo 2>/dev/null'

        John
--

 
 
 

Using Time Command With Command That Redirects Output.

Post by Gazz » Sun, 19 Jun 2005 03:44:39




>>When I did this:

>>time ls foo 2> /dev/null

>>,where 'foo' didn't exist, I didn't get the result of the 'time' command.
>>Both the standard errors of 'time' _and_ 'ls' were sent to '/dev/null'.
>>How do I get just the standard error of the 'ls' command to go to standard
>>error?

>> I'm using BASH, 'bash --version' gives the following:  'GNU bash, version
>> 2.05b.0(1)-release (i586-mandrake-linux-gnu)'.

> Sounds like you're using an external time command instead of the bash time
> builtin - maybe it's aliased?  If so:

> time bash -c 'ls foo 2>/dev/null'

> John

Hi,

Quote:> time bash -c 'ls foo 2>/dev/null'

Thanks:  using "time --quiet bash -c 'ls foo > /dev/null 2>&1'".

Yours,
Gary Hayward.

 
 
 

Using Time Command With Command That Redirects Output.

Post by Chris F.A. Johnso » Sun, 19 Jun 2005 04:02:24



> Hi,

> When I did this:

> time ls foo 2> /dev/null

> ,where 'foo' didn't exist, I didn't get the result of the 'time' command.
> Both the standard errors of 'time' _and_ 'ls' were sent to '/dev/null'.
> How do I get just the standard error of the 'ls' command to go to standard
> error?  BTW, this:

> time ls foo

> ,again where 'foo' doesn't exist, gives 'no such file' error messages on
> standard output for _both_ the 'time' _and_ 'ls' commands.

     Mandrake's bash has the internal time command disabled. (Other
     distros disable other things.)

     I strongly recommend downloading the source code and compiling it
     yourself.

--
    Chris F.A. Johnson                     <http://cfaj.freeshell.org>
    ==================================================================
    Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
    <http://www.torfree.net/~chris/books/cfaj/ssr.html>

 
 
 

Using Time Command With Command That Redirects Output.

Post by Kenny McCorma » Mon, 20 Jun 2005 06:18:24




...

Quote:>     Mandrake's bash has the internal time command disabled. (Other
>     distros disable other things.)

Wow.  Really?  Any idea why?
Seriously, I'd really be interested in knowing what the thought process
behind that (and other such deformations) was.

Quote:>     I strongly recommend downloading the source code and compiling it
>     yourself.

Yup - seems clearcut to me.
 
 
 

Using Time Command With Command That Redirects Output.

Post by Chris F.A. Johnso » Mon, 20 Jun 2005 07:12:43





> ...
>>     Mandrake's bash has the internal time command disabled. (Other
>>     distros disable other things.)

> Wow.  Really?  Any idea why?

     None whatsoever.

     Last week I switched from Mandrake to Ubuntu and my POP3 filter
     and retrieval script stopped working. It turned out that bash was
     compiled without the socket code.

Quote:> Seriously, I'd really be interested in knowing what the thought process
> behind that (and other such deformations) was.

>>     I strongly recommend downloading the source code and compiling it
>>     yourself.

> Yup - seems clearcut to me.

     And uncomment "#define DONT_REPORT_SIGPIPE" in config-top.h.

     Possible also remove ":." from "#define DEFAULT_PATH_VALUE" which
     is the next item in config-top.h.

--
    Chris F.A. Johnson                     <http://cfaj.freeshell.org>
    ==================================================================
    Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
    <http://www.torfree.net/~chris/books/cfaj/ssr.html>

 
 
 

Using Time Command With Command That Redirects Output.

Post by cLIeNUX us » Mon, 20 Jun 2005 15:51:29





>...
>>     Mandrake's bash has the internal time command disabled. (Other
>>     distros disable other things.)

>Wow.  Really?  Any idea why?
>Seriously, I'd really be interested in knowing what the thought process
>behind that (and other such deformations) was.

>>     I strongly recommend downloading the source code and compiling it
>>     yourself.

>Yup - seems clearcut to me.

Redhat seems to work for, i.e. be owned by, Microsoft. This leads to
bitrot.

--

Rick (Richard Allen) Hohensee
write-in candidate, President of the United States of America
platform  ftp://linux01.gwdg.de/pub/cLIeNUX/interim/platform2
personal webpage               http://www.veryComputer.com/~rhohen
active in Usenet alt.politics                   colorg on IRC

Ground troops out of Iraq  Put the CIA under INS  Save Darfur
Semi-legalize *    Prosecute Bush     Tighten the borders
Isolate Israel   Tax churches      halve military aquisitions
government jobs for Iraq-wounded soldiers  and 9-11 survivors
please email  my platform to friends, blogs  and   countrymen          
-------------------------------------------------------------

 
 
 

1. can't redirect output of "time" command


This is the time output of the bash builtin

This is what a csh script (/usr/bin/which) finds as time (time is
not builtin in csh)

Maybe this is a special case for bash. I don't use it so I don't know.
To be sure you aren't using the (special handled?) internal time, you
should use "\":
\time some command

--
Daniel

2. Q. memory, io & processor. usage

3. How to redirect outputs from the command "time" into a file?

4. Book suggestions?

5. variable checking in sh

6. How to redirect the output of "time" command

7. Help! Need to know about DHCP asap...

8. redirecting output from "cron" command

9. Redirecting output of one command to both stdout and stderr

10. Redirect output for TAR command

11. Executing external command and redirecting its output

12. need GDB help redirect command output to variable