0

I'm creating a python script to automate dd for my raid disk. After dd is complete, i would like to perform other tasks. May i know how can i verify the statues of the dd progress using python?

os.system('sudo losetup -D -v');
os.system('sudo losetup -o 1048576 -f xxx.img');
os.system('sudo losetup -o 1048576 -f xxx.img');
os.system('sudo mdadm --assemble --verbose --force /dev/md0 /dev/loop0 /dev/loop1');
os.system('dd if=/dev/md0 of=/desktop');
(perform other task once dd is complete)
asked Nov 10, 2017 at 6:33
1
  • Use any subprocess function or Popen, that waits for the command to finish. Commented Nov 10, 2017 at 9:41

1 Answer 1

1

dd does not output anything to stdout, however, it does output to stderr. Pass in stderr=subprocess.STDOUT to get the stderr output: Documentation here

output_dd = subprocess.check_output(['dd', 'if=/dev/md0', 'of=/desktop'] stderr=subprocess.STDOUT)

you will get output like

b'# records in\n# records out\n# bytes transferred in # secs, (# bytes/sec)

where you can use regular expressions to compare file size and the perform other operations(if that's what you want)

answered Nov 10, 2017 at 12:43
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.