How to run 'time' on a function?
Code:
#!/bin/ksh Test 15: fill up partition /usr/bin/time: cannot run diskfillerfunction: No such file or directory ----- I am obviously omitting (...) a lot of the code, but the relevant part is all there. How do I 'time' a function? TIA |
Quote:
|
Rather than using the time application why not use the Bash built-in time command when timing a Bash function? This will hopefully give you ideas how to implement this:
Code:
#!/bin/bash Edit: Sorry - I just noticed you are using the ksh shell so the time builtin may not work Edit2: Just tried this in ksh and it sems to work - the amended script is here: Code:
|
Problems with using the shell built-in:
I like /usr/bin/time because it has nice output formatting options and a very easy redirection mechanism. 1) Bash has the formatting options, but I really would rather use ksh (it's mksh, by the way). 2) The 'time' built-in in mksh does not include average CPU load. 3) Both Bash and mksh output 'time' to standard error, which I don't know how to write into a file. I can do this: Code:
# { time diskfillerfunction; } 2> ./output.txt |
Quote:
http://wiki.bash-hackers.org/mirroring/bashfaq/047 |
I solved the problem. Instead of using a function to fill up the file system, I am using an external file:
Code:
/usr/bin/time -o ${OUTPUTFILE} -a -f '%C\n${FILESYSTEM}\n%E %PCPU\n' ksh ./diskfiller.sh Thanks for all the help. |
All times are GMT -5. The time now is 02:20 AM. |