/usr/bin/time Shell Scripting Function


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting /usr/bin/time Shell Scripting Function
# 1  
Old 10-11-2011
/usr/bin/time Shell Scripting Function

Hello, I have made a Linux Shell Script that downloads 6 files from the Internet and then deletes them. Now i want to use the function "/usr/bin/time" and "bc" to calculate how long the avergate run time for the shell script is. I therefore need to do it 100 times. My shell script code is below:



Code:
#!/bin/bash/
for I in {1..6}
do
        echo "Downloading file number $I "
        wget --user=os --password=yda http://osyda50.hive.no/0$I.html

        echo "Deleting file number $I "
        rm 0$I.html
done

# 2  
Old 10-11-2011
Code:
#!/bin/bash/

That won't work. Try:

Code:
#!/bin/bash

There's no /usr/bin/time on my or most systems. 'time' is generally a shell builtin.

It also doesn't output data in a format very amenable to processing.

Since you have BASH you have the seconds variable.

Code:
START="$SECONDS"

for ((N=0; N<100; N++))
do
        for I in {1..6}
        do
                echo "Downloading file number $I "
                wget --user=os --password=yda http://osyda50.hive.no/0$I.html

                echo "Deleting file number $I "
                rm 0$I.html
        done
done

AVGDURATION="$(( (SECONDS-START)/100 ));

echo "Avg duration is $AVGDURATION"

Also: wget can download more than one file at once, and rm can delete more than one file at once. If you use wget on several files at once it's much faster, since you don't need to disconnect and reconnect for each individual file. You can get rid of your original for-loop completely:

Code:
wget --user=os --password=yda http://osyda50.hive.no/0{1..6}.html
rm 0{1..6}.html

# 3  
Old 10-11-2011
Thank you for your reply Mr Corona688.

My task was:
Quote:
My task
Create a shell script for bash(1), which calculates the average turnaround for
the script. The incision should be based on one hundred runs. For measurement of sciptets turnaround use time(1). For calculating
the average turnaround use bc(1)
Quote:
The bash has a built-in command called 'time'. For the bash script you create to use gnu version, you must enter the path to this program, rather than just 'time', or the embedded version is used. Which command (1) can be used to find the path to commands.
Code:
:/$ which time
/usr/bin/time

# 4  
Old 10-11-2011
We have a homework forum and homework rules, which you're not in and not following, respectively. Please do so.
# 5  
Old 10-11-2011
Oh, well, can you help me with the code? It is my third script in Linux. I really need to learn this.

This is my bash script:
Code:
#!/bin/bash

/usr/bin/time
for I in {1.100}
do
        sh 1b.sh | bc
done

# 6  
Old 10-11-2011
We have a homework forum and homework rules, which you're not in and not following, respectively. Please post in the homework forum, and please obey its rules. We can't help you until you do.
# 7  
Old 10-11-2011
Ok, thank you for the good advice.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. BSD

FreeBSD: /usr/bin/ld not looking in /usr/local/lib

I'm not sure if this is the default behavior for the ld command, but it does not seem to be looking in /usr/local/lib for shared libraries. I was trying to compile the latest version of Kanatest from svn. The autorgen.sh script seems to exit without too much trouble: $ ./autogen.sh checking... (2 Replies)
Discussion started by: AntumDeluge
2 Replies

2. Shell Programming and Scripting

Possible to use /usr/bin/watch to call a function?

I want to have a script both define functions and have the ability to run an external program calling one of them. This is the simplified construct: #!/bin/bash foo() { echo "this is foo" } bar() { echo "this is bar" } case "$1" in one) foo ;; two) export... (1 Reply)
Discussion started by: graysky
1 Replies

3. Shell Programming and Scripting

/usr/local/bin/expr function not working

Legends, I am not able to set "expr" function in ksh script. Below is the sample code i used, and output is as "Syntax error" Please help me to come out of it. OUTPUT (9 Replies)
Discussion started by: sdosanjh
9 Replies

4. OS X (Apple)

When to use /Users/m/bin instead of /usr/local/bin (& whats the diff?)?

Q1. I understand that /usr/local/bin means I can install/uninstall stuff in here and have any chance of messing up my original system files or effecting any other users. I created this directory myself. But what about the directory I didn't create, namely /Users/m/bin? How is that directory... (1 Reply)
Discussion started by: michellepace
1 Replies

5. Solaris

How do I link ld in /usr/ucb/ to /usr/ccs/bin?

Hi all, below is the problem details: ora10g@CNORACLE1>which ld /usr/ucb/ld ora10g@CNORACLE1>cd /usr/ccs/bin ora10g@CNORACLE1>ln -s /usr/ucb/ld ld ln: cannot create ld: File exists ora10g@CNORACLE1> how to link it to /usr/ccs/bin? (6 Replies)
Discussion started by: SmartAntz
6 Replies

6. UNIX for Dummies Questions & Answers

Differences between time command and usr/bin/time

I wondered if someone could point out the differences between the time commmand and usr/bin/time and the accuracy one might have over another. Also, is there a website or two a person could maybe link for me to describe the differences? Thank you for your time. (2 Replies)
Discussion started by: icedrake
2 Replies

7. UNIX for Dummies Questions & Answers

/usr/bin/time

thanks for your recent post. i have this command /usr/bin/time find /usr -name socket.h -print/usr/bin/time find /usr -name socket.h -print which i have ran on my personal linux machine. I dont know how to interpret this command...does it mean that find the names in the usr directory and print it... (1 Reply)
Discussion started by: BigTool4u2
1 Replies

8. UNIX for Dummies Questions & Answers

/bin/sh: /usr/bin/vi: No such file or directory when doing crontab

I just set up an ftp server with Red Hat 5.2. I am doing the work, I'm baby stepping, but it seems like every step I get stuck. Currently, I'm trying to set up a crontab job, but I'm getting the following message: /bin/sh: /usr/bin/vi: No such file or directory. I see that vi exists in /bin/vi,... (3 Replies)
Discussion started by: kwalter
3 Replies
Login or Register to Ask a Question