Jump to content

command time : missing --help and other options


Marcation
Go to solution Solved by arox,

Recommended Posts

  • Solution

"time" is "built in" into the shell.

 

In order to use the full version described by "man", you should first install the full version in /usr/bin/time :

 

# apt-get install time.

 

And call it with the full path.

 

Also, when man fail to give doc because a package is missing, just google "man cmd".

Link to comment
Share on other sites

Thanks to arox and my bad : I was trying to use some full version's option in the built in version of time. 
No need to install time, it's done in armbian, just give the full path\command :

 

root@Bpi2+:~# time -f

-f: command not found

 

real 0m0,484s

user 0m0,396s

sys 0m0,089s

root@Bpi2+:~# which time

/usr/bin/time

root@Bpi2+:~# /usr/bin/time -f

/usr/bin/time: option requires an argument -- 'f'

Usage: /usr/bin/time [-apvV] [-f format] [-o file] [--append] [--verbose]

       [--portability] [--format=format] [--output=file] [--version]

       [--quiet] [--help] command [arg...]

root@Bpi2+:~# /usr/bin/time -f "%E" curl www.orange.fr

0:00.27

 

In such case type "type time" and the shell will inform you (is a shell keyword").

Thank You again I wanted to script some test and collect the results and this format is useful for this.

 

My next step is to remove the ':' in the output (is not trivial to combine 'time' and pipe without writing the output in a file, may be I have to try something else).

Be patient I can only write one post/day....

 

It's nice to have so small SBC and so large facilities and community.  Thank You Armbian !

 

@Werner & @Igor Thank You for replying (maybe too fast ?) but You are wrong when You think that I did'nt red the man pages ... it was more complex.

 

Link to comment
Share on other sites

In shell, pipes and awk are your bests friends : perhaps something like this :

 

$ mkfifo /tmp/timefifo

$ awk -W interactive -F: '{printf("cmd=%s s=%f\n", $1, $2*60+$3)}' <>/tmp/timefifo > /tmp/stats &  

 

$ /usr/bin/time -o /tmp/timefifo -f "%C:%E" ls -l
$ /usr/bin/time -o /tmp/timefifo -f "%C:%E" ls
$ /usr/bin/time -o /tmp/timefifo -f "%C:%E" who


$ cat /tmp/stats

cmd=ls -l s=0.700000
cmd=ls s=0.070000

cmd=who s=0.000000

 

$ killall awk

N.B.  : <> open the pipe in read/wite mode to prevent it to be closed when "time" send EOF.

Link to comment
Share on other sites

I have tested the mamed pipe thru three small scripts :

 

=> the first one is called by snmpcd (snmp formating)

echo .1.3.6.1.2.1.25.1.8.0

echo Gauge32

bash /usr/bin/local/secondscript

 

=> the secondscript with awk and named pipe :

FIFO="/tmp/timefifo"

[[ -e $FIFO ]] &&  rm $FIFO    # if present then suppress it

mkfifo $FIFO 

awk -W interactive '{printf("%-6d \n", $1*1000)}' <> $FIFO > /tmp/stats &

/usr/bin/time -o $FIFO -f "%e" /usr/bin/thirdscript

cat /tmp/stats

killall awk

[[ -e $FIFO ]] && rm $FIFO

 

=> the third script :define the operation You want to know the during :

 

URL="example.html"

for i in `seq 1 20`;

do

         curl $URL > /dev/null 2>&1

done

 

********   It works, but there is a more simple solution

echo .1.3.6.1.2.1.25.1.8.0

echo Gauge32

before=$(date +%s%N)

curl http://example.html > /dev/null 2>/dev/null

after=$(date +%s%N)

echo $((((after-before))/1000))

********** result in microsecond

On 6/22/2021 at 5:33 AM, Werner said:

Often the best solutions are the simplest ;)

 

 

Link to comment
Share on other sites

"called by snmpcd (snmp formating)"

 

As you and Werner say : the best solutions are often the simplest. The problem is to find what is really the simplest and to make the difference between simple and basic in a use case.

 

(This is just a bit of general thinking (and nostalgy), as I have no idea about what you are working on).

 

The **simple** network management protocol is surely basic but I never found it was simple and it has been a long time since I saw someone care about it.

 

One more time, this is just general thinking, but I feel we use today a lot of complicated but no so powerful technologies in IT. Linux is a unix derivative, UNix  has been designed by people who wanted a simple but powerful system after having worked on MULTix.

 

I try to keep that in mind. But it is not always easy and cannot be achieve if we want our computers to also toast bread and do the laundry. 

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines