I have to chmod and chown hundreds of thousands of files as part of a migration script. Each command takes about an hour and a half to complete. I realized these two operations can be run at the same time which cuts down on running time, which I confirmed by testing in the shell.
I know the trick of pushing commands into the background with '&', but I need to make sure both processes finish before proceeding with the rest of the script.
Thanks
Use the
wait
command.This demo:
Produces this output:
There's a fifteen second pause before the last two lines are output.
You can capture the pid and use wait.
(should work with bash; details may differ on other shell types)
If you need to make sure that both processes are finished before proceeding to the next step, a simple solution would be to write something to a file and check it. Just do a head or cat on the file (with default value 0) and add 1 to the first line. If you detect 2, then both processes are completed. Of course the addition should be done at the very bottom of your scripts.