Solved

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

Posted on 2007-03-27
3
613 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 34

Accepted Solution

by:
Duncan Roe earned 250 total points
ID: 18804085
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
ID: 18806309
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
ID: 18806476
Would be more efficient to have
exec pyzor --homedir /etc/mail/spamassassin/.pyzor report <$1
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
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 how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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.

740 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