I am trying to get timing paramters from a CGI program. date is just a command for example used here.
when I do: time { date; } everything is good.
when I do: time -o file { date; } I get time -o file { date; } bash: syntax error near unexpected token `}'
How do I correctly issue the command with an option for -o file to output the data to a file.
Thanks,
Jerry
On Tue, Jan 13, 2009 at 9:14 AM, Jerry Geis geisj@pagestation.com wrote:
I am trying to get timing paramters from a CGI program. date is just a command for example used here.
when I do: time { date; } everything is good.
when I do: time -o file { date; } I get time -o file { date; } bash: syntax error near unexpected token `}'
How do I correctly issue the command with an option for -o file to output the data to a file.
The man page for time gives the usual information and includes only the -p option, but then, below the 'see also' section which usually signifies the end, it goes on to discuss the 'GNU version' which includes additional options. Apparently, the time command we get with CentOS is not the GNU version because it pukes on all of the stated options. So why is all that info in the man page and where is this elusive GNU version? I checked both C4 and C5 and neither supported the additional options.
Unless somebody else can shed some more light on this, I guess you are stuck with output redirection provided by your chosen shell.
Jeff wrote:
Unless somebody else can shed some more light on this, I guess you are stuck with output redirection provided by your chosen shell.
Try /usr/bin/time instead of 'time', I believe 'time' is a internal command for bash as well.
Threw me off for a while as well. (e.g. redirecting time output to a file does not work unless you call /usr/bin/time, even redirecting stderr, at least last time I tried)
nate
Hi,
On Tue, Jan 13, 2009 at 13:24, nate centos@linuxpowered.net wrote:
Try /usr/bin/time instead of 'time', I believe 'time' is a internal command for bash as well.
Right.
However, /usr/bin/time won't accept the syntax above, this will not work: $ /usr/bin/time { date; }
Of course you can: $ /usr/bin/time date
Or: $ /usr/bin/time sh -c '{ date; }'
Or: $ /usr/bin/time bash -c '{ date; }'
If you want to use the external binary instead of the built-in, but you don't want to type the full path, you can use the trick to add a backslash in front of the command name: $ \time -o file date
If you want to use the built-in "time" available in bash, you can get a reference to its options with the command: $ help time
You will see that the only option it supports is -p to slightly change the format, but not -o for the output. You should do redirection with
and/or 2> to write to a file.
Another advantage of the built-in is that it does time a full pipeline. For example, this will time both date and grep: $ time date | grep Sat
While this will time date only: $ /usr/bin/time date | grep Sat
HTH, Filipe
On Tue, Jan 13, 2009, Jerry Geis wrote:
I am trying to get timing paramters from a CGI program. date is just a command for example used here.
when I do: time { date; } everything is good.
when I do: time -o file { date; } I get time -o file { date; } bash: syntax error near unexpected token `}'
How do I correctly issue the command with an option for -o file to output the data to a file.
Why aren't you using standard i/o redirection?
time { date ; } > file
OR to append to the file
time { date ; } >> file
Bill