I'm trying to approximate the computer's write speed using dd:
dd if=/dev/urandom of=/dev/null bs=1K count=10000
which gives the following output
10000+0 records in
10000+0 records out
10240000 bytes (10 MB) copied, 0.746313 s, 13.7 MB/s
How can I get the '13.7 MB/s' into a bash variable? I've tried piping the output from dd to progs like awk, sed and grep to no avail.
Ultimately, I'm calling this via os.system(...)
from within a python script. If anyone knows of a more direct way to get a similar result inside python I'd be interested in that also. I'm trying to predict how long a file copy will take, based on the file size.
Any help would be greatly appreciated.
Best Answer
The problem is your designated output from dd goes to
STDERR
and notSTDOUT
so you have to redirectSTDERR
as well and not onlySTDOUT
.For bash and zsh you can use
|&
instead of|
which will also redirectSTDERR
toSTDIN
of the second command, e.g:The more general approach is to redirect STDERR explicitly with
2>&1
, e.g:For the python part have a look at at the subprocess module and
Popen
in particular.