Operating System - HP-UX
1837196 Members
2360 Online
110115 Solutions
New Discussion

Re: Using 'find' to send multiple child processes to the bg

 
SOLVED
Go to solution
spex
Honored Contributor

Using 'find' to send multiple child processes to the bg

Hello everyone,

I'm using sh-posix under B.11.11.

I'm trying to come up with a find construct to send multiple child processes to the bg. This will be used for parallel backup of datafiles located anywhere within a directory structure.

Here's what I've tried so far as a test:
# find /u02/oradata/mysid -name '*.dbf' -type f -exec sh -c "sleep 60 &" \;

# ps -f | grep sleep
shows that one sub-process running 'sleep' exists for each .dbf file. So far so good. However, when I try to pass the current path name to -exec, I get the following:
# find /u02/oradata/mysid -name '*.dbf' -type f -exec sh -c "ll {} &" \;
{} not found
{} not found
{} not found
{} not found
{} not found
{} not found

Note that I've tried to accomplish the same thing with '-exec &' (instead of 'sh -c " &"') and 'find ... | xargs -i ' with no luck.

Ultimately, I would like to copy all .dbf files within a directory structure in parallel, 'wait' for all the child processes to terminate, and then repeat for a new directory structure.

If anyone has any suggestions, I would appreciate reading them.

Thanks,

PCS
5 REPLIES 5
Steven E. Protter
Exalted Contributor

Re: Using 'find' to send multiple child processes to the bg

Shalom,

If this is being done to make things copy faster or involves large files, its likely to work more slowly than a sequential file copy. Head thrashing will probably occur.

Try enclosing the current path in quotes so teh special characters don't confuse find.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Pete Randall
Outstanding Contributor
Solution

Re: Using 'find' to send multiple child processes to the bg

What about a for loop instead?

for FILE in `find /u02/oradata/mysid -name '*.dbf' -type f`
do
your_desired_command
done

I haven't tested but I think that accomplishes your goal.


Pete

Pete
spex
Honored Contributor

Re: Using 'find' to send multiple child processes to the bg

Steven,

With this particular server/storage combination, it is definitely faster to copy files in parallel.

Pete,

Of course! I was so intent on doing everything within 'find' that I didn't think of using an external loop. Thanks for your insight.

PCS
Dennis Handly
Acclaimed Contributor

Re: Using 'find' to send multiple child processes to the bg

If you have too many files for an external for loop, have -exec invoke a script then invokes the real script with "&".

>Pete:for FILE in `find /u02/oradata/mysid -name '*.dbf' -type f`; do

You do know you should replace `` by $()?
for FILE in $(find /u02/oradata/mysid -name '*.dbf' -type f); do
Pete Randall
Outstanding Contributor

Re: Using 'find' to send multiple child processes to the bg

Dennis,

I *SHOULD*??? When the Posix police come around and insist that I change not only my ingrained habits, but all my old scripts, and indicate that they're willing to pay for all this effort, I'll *THINK* about it.


Pete

Pete