PID Capture and Return Codes

I have a process that copies files from a main storage server to main other servers. We are attempting to speed up the processing and have thought that the best method would be to use concurrent file copying.

What was suggested is that we change from using a simple RCP and waiting for it to complete, that we append the command with an "&" to have it run in the background and allow the script to keep at maximum 30 processes (RCPs) executing simulatenously.

So we have a loop and we are looping through our RCPs. My questions is this...

How can we capture the return codes from the RCPs that were running in the background? How can we capture the PID that is created?

After all RCPs have completed successfully, we would like to then go back and check on the return codes of each and see that they all ran successfully. We COULD remsh out to each server after the fact to check that the file exists but this too will add to process time.

Any suggestions, comments or answers to my question (PID capture and return code)?

You could write a little wrapper script to call rcp and write the return code to a file and then background the script?

e.g. wrapper script:

echo PID = $$ > /tmp/rcp.$$.log
echo Running rcp $@ >> /tmp/rcp.$$.log
rcp $@
RESULT=$?
echo RESULT = ${RESULT} >> /tmp/rcp.$$.log

Fantastic suggestion and it was exactly what I wanted. As soon as I started reading your reply I smacked myself in the forehead and sighed. So obvious now...

Taking on too many projects at once makes my head hurt.

Thanks again!

The $$ in the script is the PID of the script not rcp of course...