Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
-
The problem statement, all variables and given/known data:
Make a bash script that calculates average runtime for the first two scripts you made. The average should be based on 100 runs of the scripts. For measuring the runtime you shall use the built in GNU time(1) function (/usr/bin/time). For calculating the average (by addition and floatdivition) use bc(1). -
Relevant commands, code, scripts, algorithms:
bash
/usr/bin/time
bc
return values from the built in time:
0.00user 0.01system 0:00.11elapsed 13%CPU (0avgtext+0avgdata 0maxresident)k0inputs+0outputs (0major+529minor)pagefaults 0swaps
- The attempts at a solution (include all code and scripts):
script 1
#!/bin/bash
for I in {1..6}
do
echo "downloading 0$I.html"
wget filefromurlhere <-(not adding this as it requires a password and stuff)
echo "deleting 0$I.html"
rm 0$I.html
done
script2
#!/bin/bash
for I in {1..6}
do
echo "downloading 0${I}.html"
wget "file from url here"
wait
echo "deleting 0${I}.html"
rm "0${I}.html"
done
script3 for average runtime.
#!/bin/bash
#/usr/bin/time
for I in {1.100}
do
echo $(time script1.sh 2>&1)+
done | sed 's/+$//\n/' | bc
- Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Norwegian University of Science and Technology NTNU, Trondheim, Norway, Svein Erik Bratsberg, TDT4186 Operativsystemer, h t t p : / / w w w . i d i . n t n u . n o / e m n e r / t d t 4 1 8 6 / (can't post urls, remove spaces ;D )
Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
I'm in need of the elapsed return value from the time (atleast that's what makes sense to me), added up for 100 run throughs and divided by 100 to find the average time, using bc to do it all. just not sure how to get exactly those numbers from all the junk I get returned with the built in time function.
I know my 3rd script might be far off, but I'm a real newbie to linux scripting
---------- Post updated at 10:54 PM ---------- Previous update was at 06:00 PM ----------
Well I found I could use awk like this, but I really need it to do the calculations in bc. can I just replace awk with bc in this and have it do what it's supposed to? D:
usr/bin/time -p {myScript} | grep elapsed | awk '{print $2}' >> datafile.dat
awk 'BEGIN {t=0.0;c=0;a=0.0;} {t+=$1; c++;} END {printf("Total %f Count %d Avg %f\n", t, c, t/c);}' < datafile.dat
---------- Post updated 10-12-11 at 06:06 AM ---------- Previous update was 10-11-11 at 10:54 PM ----------
I'll update in a new post instead of editing, I've had a pretty major breakthrough, just being stuck trying to get my stdin into my calculations.
script1
!#/ in/bash
for I in {1..6}
do
wget --quiet myUrl/file$I.html
done
rm 0{1..6}.html
script2
#!/bin/bash
for I in {1..6}
do
wget --quiet myUrl/file$I.html &
done
wait
rm 0{1..6}.html
script3 for runtime calculations
#!/bin/bash
for I in {1..5}
do
/usr/bin/time -f "%E (elapsed)" ~/script1.sh 2>&1
echo 'x+stdout' <--- how to get the value of stdout for calculations?
done
echo 'scale=20;x/100' | bc
echo "gjennomsnittstid for skript1a er $x"
for I in {1..5}
do
/usr/bin/time -f "%E (elapsed)" ~/script2.sh 2>&1
echo 'y+stdout' | bc <--- how to get the value of stdout for calculations?
done
echo 'scale=20;y/100' | bc
so yeh. I've rerouted the elapsed time from my time call into stdout, but how do I get it back so I can calculate on it?