Ugh... I should have realized this earlier.
Here's the crux of the problem: There are two distinct time commands (at least). A stand-alone executable, and (for bash) a shell built-in command.
When you specify to execute "time
something", it defaults to the shell built-in, and as far as I can tell, there's no way to pass that version any information (such as "send your output to a file").
If you invoke the command with an absolute/relative path to the stand-alone executable, then you can give it arguments. For instance, on my system, the time program is installed in /usr/bin:
Code:
/usr/bin/time du -hs ${HOME}
Anyway, you mentioned you have version 1.7 (same as on mine), and there's a -o option to direct where to send the output. In fact, you have a lot of flexibility in what information it reports; all of it documented in the man page of course.
So I would suggest a script like this:
Code:
#!/bin/bash
MAX_CHECKS=100
current_check=0
elapsed_time=0
while [ ${current_check} -lt ${MAX_CHECKS} ]
do
/usr/bin/time -f "%e" -o /tmp/current_time_used iwlist ath0 scanning >>scan_op.txt
current_time=$( cat /tmp/current_time_used )
let elapsed_time=elapsed_time+current_time
let current_check=current_check+1
done
let elapsed_time=elapsed_time/${MAX_CHECKS}
echo "average time per check: ${elapsed_time}"
Something to note: I haven't even attempted to run that script. There may be (probably are) problems with it, but they'll probably be easy to iron out. Also, the shell does
integer division, meaning your average time at the end will be reported as whole seconds (not fractional). If that's not what you want, then you'll need to use something like bc to get greater accuracy.