View Full Version : Find -exec output piping
DCM36
July 7th, 2011, 03:21 AM
I'm trying to do something similar to the following, but haven't quite figured out the correct syntax
find . -print -exec python ./pescanner.py {} | tee ./reports/{}.txt \;
What I'm wanting to do is:
Use find to find all the files in the current directory
Run the pescanner.py python script against each file, which outputs its findings to the terminal/STDOUT
Output the pescanner.py findings to individual text files in the reports subdirectory
Thanks for any help/suggestions
pafoo
July 7th, 2011, 03:36 AM
for loop is better for that, try this on the command line cd to current directory
for item in $(ls .); do /home/pythonscanner.py /home/$item | tee /home/reports/$item; done
make sure to use absolute path
also in your python script if you add on the first list #!/usr/bin/python you dont have to use python to run the python script.
DCM36
July 7th, 2011, 03:54 AM
for loop is better for that, try this on the command line cd to current directory
for item in $(ls .); do /home/pythonscanner.py /home/$item | tee /home/reports/$item; done
make sure to use absolute path
also in your python script if you add on the first list #!/usr/bin/python you dont have to use python to run the python script.
That does work as expected, however is there a way to get things to work recursively? It does run the python script against each file recursively, however the tee report output only ends up in the name of the parent folder.
Example of setup/what happens:
Folder_A
file_a
file_b
Folder_B
file_c
file_d
Will output to reports with folder_a.txt and folder_b.txt with the results of the python output from file_b and file_d respectively since tee isn't appending
pafoo
July 7th, 2011, 04:06 AM
use tee -a to append. Im not really sure what you mean it puts the text only in the parent directory. Cut and paste what you did.
Powered by vBulletin® Version 4.2.2 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.