Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2007-03-27
3
Medium Priority
?
616 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 35

Accepted Solution

by:
Duncan Roe earned 1000 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 35

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
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…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

721 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