Solved

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

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
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…
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.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

810 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