LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   How to execute multiple commands with find and -exec... (https://www.linuxquestions.org/questions/linux-general-1/how-to-execute-multiple-commands-with-find-and-exec-403024/)

tomstratton 01-13-2006 03:30 PM

How to execute multiple commands with find and -exec...
 
I see several references to the ability to execute multiple commands on the results of a single find command.

What I am trying to do is use a flag to track which files have been processed by a recurring script.

I find the files that do NOT have the flag set, then I process them. Next I want to set the flag.

Problem is that the list of files returned by the flag will be different because time elapses between the first and second incidence of the find commands.

So, what I want to do is use a single list to execute both commands.

Anyone have a single line solution that does NOT involve writing a script, or a solution that involves storing the results of the find in a temporary file?

Thanks

Tom


EG:
find ./ -flags noopaque -exec chmod a+x
fins ./ -flags noopaque -exec chflags opaque

repeat every 10 minutes

Note - this is an example only - these are not the exact commands I am running...

acid_kewpie 01-13-2006 03:34 PM

find ./ -flags noopaque -exec cmd1 -exec cmd2

painfully simple huh?

d3funct 01-13-2006 03:39 PM

Why not put it in a crontab?
10 * * * * * find ./ -flags noopaque |xargs chmod a+x && chflags opaque 2>&1 >/dev/null

tomstratton 01-13-2006 04:00 PM

Ouch
 
Quote:

Originally Posted by acid_kewpie
find ./ -flags noopaque -exec cmd1 -exec cmd2

painfully simple huh?



OUCH!

Thanks!

zaphod 64 05-25-2009 02:21 AM

Quote:

Originally Posted by tomstratton (Post 2046201)
OUCH!

Thanks!

Does not work with Solaris 10:

find . -name "Batch*.txt" -exec cat {} -exec echo "============" \;
...
cat: cannot open -exec
cat: cannot open echo
cat: cannot open ============

I really would appreciate any help! :)

colucix 05-25-2009 02:34 AM

Each -exec action must terminate with an escaped semi-colon, otherwise all the rest of the line is interpreted as the command to execute.
Code:

find . -name "Batch*.txt" -exec cat {} \; -exec echo "============" \;

zaphod 64 05-26-2009 03:26 AM

Quote:

Originally Posted by colucix (Post 3551758)
Each -exec action must terminate with an escaped semi-colon, otherwise all the rest of the line is interpreted as the command to execute.
Code:

find . -name "Batch*.txt" -exec cat {} \; -exec echo "============" \;

Thanks! This is it!


All times are GMT -5. The time now is 04:35 AM.