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
Solved

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

Posted on 2007-03-27
3
612 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
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Suggested Solutions

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
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.

839 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