I have a bash script which calls an external program I cannot modify. The first stage of this program uses high IO and the second stage uses almost no IO, instead it uses a lot of CPU, it does not provide any output which indicates which stage it is on. I want to call this program, wait until it's done with the IO-heavy stage, and then continue running the rest of my script. In pseudocode it would be something like this
execute externalscript
while total io for last 30 seconds > 1MB;do sleep 30s;done;continue script
<.. rest of script..>
What methods could I use to monitor the IO? I am familiar with iotop, just wondering if there's a more direct way than parsing its output.