Solved

Help with FIND command and redirecting found file to programs std input

Posted on 2007-03-27
3
608 Views
Last Modified: 2008-01-09
Can someone give me a hand with the correct syntax for a FIND command. Normally I dont have a problem but in this case I need to search a directory and for every file run a command and pass the file to it as standard input. Because if this I have to 'cat |' or use '<' to redirect and therefore need to quote it. However when I run the command I get errors like :-

find: pyzor --homedir /etc/mail/spamassassin/.pyzor report </root/sa-learn/spam/553.: No such file or directory

This is the current find example I am using :-
find /root/sa-learn/spam/*. -exec "pyzor --homedir /etc/mail/spamassassin/.pyzor report <{}" \;

If I run "find: pyzor --homedir /etc/mail/spamassassin/.pyzor report </root/sa-learn/spam/553.: No such file or directory" manually it works so the patch is correct.
0
Comment
Question by:grblades
  • 2
3 Comments
 
LVL 34

Accepted Solution

by:
Duncan Roe earned 250 total points
Comment Utility
Where you have a problem is putting quotes around the target of -exec - the entire string is used as a command name so you get the error message you see.
Unfortunately, -exec does not support input redirection: I just tried:

07:52:28$ find files/* -exec cat \< {} \;
cat: <: No such file or directory
# Comment
1:Test-1
2:Test-2
3:Test-3
4:Test-4

cat saw "<" as a separate argument. (It processes all its args so it output the found file as well).

What you need to do is write a small shell script and have find obey that.:

08:20:04$find files/* -exec ./mycat {} \;
# Comment
1:Test-1
2:Test-2
3:Test-3
4:Test-4
08:20:05$ cat mycat
#!/bin/sh
exec cat <$1
0
 
LVL 36

Author Comment

by:grblades
Comment Utility
Thanks for the tip. I used :-
find /root/sa-learn/spam/*. -exec pyzorreport {} \;

pyzorreport :-
#!/bin/sh
pyzor --homedir /etc/mail/spamassassin/.pyzor report <$1
0
 
LVL 34

Expert Comment

by:Duncan Roe
Comment Utility
Would be more efficient to have
exec pyzor --homedir /etc/mail/spamassassin/.pyzor report <$1
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now