How to static the average value


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to static the average value
# 1  
Old 04-22-2009
How to static the average value

Hi all,

Sorry I make a mistake,the title should be "How to statistic the average value "

I do five times about "mv 123 to 456"
and do five times about "mv 456 to 123"
As we know,"time" can get the real usr sys value,
I want to get the average real,usr,sys of "mv 123 to 456" and "mv 456 to 123"


Quote:
#!/bin/bash
for ((i=1;i<=10;i+=1));do
echo "mv 123 to 456 the $i \n"
time mv 123 456;
echo "mv 456 to 123 the $i \n"
time mv 456 123;
done

I named it "test"

leiyang@leiyang-laptop:~$ ./test
mv 123 to 456 the 1 \n
real 0m0.005s
user 0m0.004s
sys 0m0.000s
mv 456 to 123 the 1 \n
real 0m0.004s
user 0m0.000s
sys 0m0.004s
mv 123 to 456 the 2 \n
real 0m0.004s
user 0m0.000s
sys 0m0.004s
mv 456 to 123 the 2 \n
real 0m0.004s
user 0m0.000s
sys 0m0.004s
mv 123 to 456 the 3 \n
real 0m0.008s
user 0m0.000s
sys 0m0.004s
mv 456 to 123 the 3 \n
real 0m0.005s
user 0m0.000s
sys 0m0.008s
mv 123 to 456 the 4 \n
real 0m0.004s
user 0m0.000s
sys 0m0.004s
mv 456 to 123 the 4 \n
real 0m0.002s
user 0m0.000s
sys 0m0.004s
mv 123 to 456 the 5 \n
real 0m0.002s
user 0m0.000s
sys 0m0.000s
mv 456 to 123 the 5 \n
real 0m0.002s
user 0m0.000s
sys 0m0.000s
for example :
for "mv 123 to 456"
I want to got real_average_123_to_456=(real+real+real+real+real)/5 (here real is for "mv 123 to 456'' in each time),also want to get usr_average_123_to_456,sys_average_123_to_456

for "mv 456 to 123"
I want to got real_average_456_to_123=(real+real+real+real+real)/5 (here real is for "mv 456 to 123'' in each time),also want to get usr_average_456_to_123,sys_average_456_to_123

how can I modify above code.I'm poor in bash shell.please show me a light

Last edited by yanglei_fage; 04-22-2009 at 02:54 PM..
# 2  
Old 04-22-2009
bash does not do floating point math by itself. Since you have to convert the output of time into something you can do math on, this whole thing scream "use perl" to me.

As a hint, though, look at your man page for time. On Linux you can do "time -p" and it will output in a decimal value instead of tacking on the minute and second units.
# 3  
Old 04-22-2009
Quote:
Originally Posted by kodak
bash does not do floating point math by itself
But apparently ksh does:
Code:
colemar@deb:~$ echo $((1.0/7))
bash: 1.0/7: syntax error: invalid arithmetic operator (error token is ".0/7")
colemar@deb:~$ ksh
$ echo $((1.0/7))
0.142857142857142857

# 4  
Old 04-22-2009
hah, sweet. I never use ksh, thanks.
# 5  
Old 04-23-2009
Thanks for the reply, If we use ksh, How can we got the answer.
Anyone can post the code?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Have a static IP for net0

Hi, Here is what I get within Solaris. huamin@SOL11I:~$ ifconfig -a lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1 inet 127.0.0.1 netmask ff000000 net0: flags=1004843<UP,BROADCAST,RUNNING,MULTICAST,DHCP,IPv4> mtu 1500 index 2 inet 0.0.0.0 netmask... (24 Replies)
Discussion started by: HuaMin
24 Replies

2. Programming

Static variables in C++

Are the following equivalent? static int df, dl, du, count; static int df; static int dl; static int du; static int count; (7 Replies)
Discussion started by: kristinu
7 Replies

3. Programming

Even the Static cURL Library Isn't Static

I'm writing a program which uses curl to be run on Linux PCs which will be used by a number of different users. I cannot make the users all install curl on their individual machines, so I have tried to link curl in statically, rather than using libcurl.so. I downloaded the source and created a... (8 Replies)
Discussion started by: BrandonShw
8 Replies

4. UNIX for Dummies Questions & Answers

How to tell if i am using DHCP or Static

Hey guys , YEs this is probably silly for most but i am new to this forum and solaris . i am curious to know if the ip address we have for our solaris server is static or dhcp . how can i tell ? will ifconfig -a tell me this ? or other commands? Thanks in advance (1 Reply)
Discussion started by: xdrivex
1 Replies

5. Linux

Could static library include static library?

I have some static library(libxxx.a libyyy.a). And I want to generate my library(libzzz.a), libzzz.a will use libxxx.a and libyyy.a I wan't my application only use libzzz.a, (means libzzz.a had include libxxx.a, libyyy.a), how can I do that? Thank you. example: I have zzz.c. I do ... (4 Replies)
Discussion started by: freemagic
4 Replies

6. IP Networking

I need HELP to Set up Coyote Linux router with 1 static IP & 64 internal static IP

hello, i need help on setting my coyote linux, i've working on this for last 5 days, can't get it to work. I've been posting this message to coyote forum, and other linux forum, but haven't get any answer yet. Hope someone here can help me...... please see my attached picture first. ... (0 Replies)
Discussion started by: dlwoaud
0 Replies

7. UNIX for Dummies Questions & Answers

Static Route

Hi, Request you to please tell me the command or the process to add the static route in redhat linux. Thanks in Advance. Regards Arun (2 Replies)
Discussion started by: Arun.Kakarla
2 Replies

8. IP Networking

static route ?

Hi, I have a machine that sits on 10.2 network. I need to ssh from this to another box that is on both 10.125 & 10.140 VLANs what should I need to do? Thanks! (3 Replies)
Discussion started by: chaandana
3 Replies

9. Programming

Static

What does this command exactly do cc -static example.c (6 Replies)
Discussion started by: wojtyla
6 Replies

10. IP Networking

Static IP

Is it possible, and if so, how can I assign a static IP address to my RedHat 8.0 machine. I am using a Linksys router/switch with DHCP enabled. I have a small linux/windows2000 LAN at home. I want to assign a static IP so that I can setup port forwarding to my linux machine so that I can ssh into... (7 Replies)
Discussion started by: google
7 Replies
Login or Register to Ask a Question