Run command in background by find and exec

Run command in background by find and exec

Post by Vik » Thu, 28 Apr 2005 19:08:54



Hi all
My problem is to copy a few large files parallely in background. I'm trying
to do it with find:

find * -prune -name "*sth" -size +1024000 -exec cp {} /somewhere \;

Let's say there are 5 files matching the criteria, so I'd like to have 5
bacground processes copying each of those files in background, i've tried:

find * -prune -name "*sth" -size +1024000 -exec cp {} /somewhere & \;
or \& or "&"
and I got errors.
Where am I wrong? Is it possible to do it in one line?
AIX + ksh
Best Regards
Vik

 
 
 

Run command in background by find and exec

Post by Icarus Sparr » Thu, 28 Apr 2005 20:02:04



> Hi all
> My problem is to copy a few large files parallely in background. I'm
> trying to do it with find:

> find * -prune -name "*sth" -size +1024000 -exec cp {} /somewhere \;

> Let's say there are 5 files matching the criteria, so I'd like to have 5
> bacground processes copying each of those files in background, i've tried:

> find * -prune -name "*sth" -size +1024000 -exec cp {} /somewhere & \; or
> \& or "&"
> and I got errors.
> Where am I wrong? Is it possible to do it in one line? AIX + ksh

The mistake is thinking that 'find ... -exec ...' invokes a shell to do
the work. The '&' to put a task into the background is a shell construct.

If you want a shell you have to ask for it explicitly.

find *sth -prune -size +1000k -exec ksh -c 'cp $1 /somewhere&' \{} \;

In most cases this will not be any faster than doing the 5 copies in
sequence, as the limiting factor will be I/O speed.

 
 
 

Run command in background by find and exec

Post by Vik » Thu, 28 Apr 2005 22:30:20


Dnia Wed, 27 Apr 2005 11:02:04 GMT, Icarus Sparry napisa3(a):


> The mistake is thinking that 'find ... -exec ...' invokes a shell to do
> the work. The '&' to put a task into the background is a shell construct.

> If you want a shell you have to ask for it explicitly.

> find *sth -prune -size +1000k -exec ksh -c 'cp $1 /somewhere&' \{} \;

> In most cases this will not be any faster than doing the 5 copies in
> sequence, as the limiting factor will be I/O speed.

Thank You so much :o)
I've done some tests and it is a little bit faster.
Regards
Vik
 
 
 

Run command in background by find and exec

Post by Kevin Collin » Fri, 06 May 2005 07:03:46




>> Hi all
>> My problem is to copy a few large files parallely in background. I'm
>> trying to do it with find:

>> find * -prune -name "*sth" -size +1024000 -exec cp {} /somewhere \;

>> Let's say there are 5 files matching the criteria, so I'd like to have 5
>> bacground processes copying each of those files in background, i've tried:

>> find * -prune -name "*sth" -size +1024000 -exec cp {} /somewhere & \; or
>> \& or "&"
>> and I got errors.
>> Where am I wrong? Is it possible to do it in one line? AIX + ksh

> The mistake is thinking that 'find ... -exec ...' invokes a shell to do
> the work. The '&' to put a task into the background is a shell construct.

> If you want a shell you have to ask for it explicitly.

> find *sth -prune -size +1000k -exec ksh -c 'cp $1 /somewhere&' \{} \;

> In most cases this will not be any faster than doing the 5 copies in
> sequence, as the limiting factor will be I/O speed.

You're assuming a whole lot by saying that. If the data is on multiple disks
(or RAID) on an SMP system, it could be quite a bit faster. In my environment,
where the average server has 4-8 CPUs and are Fibre-attached to Hitachi Data
Storage RAID arrays, your would be WAY wrong :)

Kevin

--
Unix Guy Consulting, LLC
Unix and Linux Automation, Shell, Perl and CGI scripting
http://www.unix-guy.com

 
 
 

1. find -exec find -exec rm

Hi
Is there a way make find running find that runs a command?
Im ok as long the second find doesnt do -exec.

        find . -type d -name .netscape \
        -exec find {} -type d -name cache \;

The above is ok but below is not.

        find . -type d -name .netscape \
        -exec find {} -type d -name cache -exec echo rm {} \; \;
                                                        ^^^^^
                                                    (how to escape them?)

//Mats

--
My code (if any) in this message are Copyright (C) 2002 Mats Blomstrand
and licensed under GNU GPL, http://www.gnu.org/licenses/gpl.html

2. Newbie Appache log question

3. running processes in background w/ fork, exec

4. sleep and wakeup

5. Running exec on a background process...

6. Smail and UUCP Problem

7. Need to find vi command to remove ^H from command man find > find.txt

8. SSRT2336 Security Vulnerability in XDR library (rev.2)

9. Command EXEC/find in a C++ program file

10. Multiple commands via -exec in find

11. error with -exec in find-command

12. Help with find: modifying {}, and multiple commands in exec

13. find command exec error