LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 01-13-2006, 04:30 PM   #1
tomstratton
LQ Newbie
 
Registered: Jan 2006
Posts: 2

Rep: Reputation: 0
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...
 
Old 01-13-2006, 04:34 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,415

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
find ./ -flags noopaque -exec cmd1 -exec cmd2

painfully simple huh?
 
Old 01-13-2006, 04:39 PM   #3
d3funct
Member
 
Registered: Jun 2001
Location: Centralia, WA
Posts: 274

Rep: Reputation: 31
Why not put it in a crontab?
10 * * * * * find ./ -flags noopaque |xargs chmod a+x && chflags opaque 2>&1 >/dev/null
 
Old 01-13-2006, 05:00 PM   #4
tomstratton
LQ Newbie
 
Registered: Jan 2006
Posts: 2

Original Poster
Rep: Reputation: 0
Ouch

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

painfully simple huh?


OUCH!

Thanks!
 
Old 05-25-2009, 03:21 AM   #5
zaphod 64
LQ Newbie
 
Registered: May 2009
Posts: 2

Rep: Reputation: Disabled
Question

Quote:
Originally Posted by tomstratton View Post
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!
 
Old 05-25-2009, 03:34 AM   #6
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
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 "============" \;
 
Old 05-26-2009, 04:26 AM   #7
zaphod 64
LQ Newbie
 
Registered: May 2009
Posts: 2

Rep: Reputation: Disabled
Thumbs up

Quote:
Originally Posted by colucix View Post
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!

Last edited by zaphod 64; 05-26-2009 at 04:27 AM. Reason: Icon added
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how can I execute two commands on exec of a find? eantoranz Programming 3 08-03-2010 05:51 PM
LXer: Execute Commands on Multiple Linux or UNIX Servers LXer Syndicated Linux News 0 12-27-2005 07:46 PM
execute multiple ssh remote commands tom221 Linux - Newbie 2 01-28-2005 02:00 PM
Multiple commands with exec! dtheorem Linux - General 1 03-14-2004 04:46 PM
error in exec of stage2 trying to execute /usr/bin/runinstall2 Catherine Brett Linux - Newbie 0 07-11-2003 01:59 PM


All times are GMT -5. The time now is 03:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration