LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   capturing output from "find" (https://www.linuxquestions.org/questions/linux-software-2/capturing-output-from-find-102499/)

wedgeworth 10-10-2003 12:29 PM

capturing output from "find"
 
i'm trying to capture the output of a find command i'm using to see which files are beyond a certain age. it will be used to report on which files i'll be deleting. examples script:



find /home/lacey/test/cleanup/ -cmin -15 -type f -print
find /home/lacey/test/cleanup/ -cmin -15 -type f -exec rm -r {} \;

the first command prints out what files are older than 15 min. the second command deletes them. i want a way to save the output from the first command, and then e-mail myself the list generated from the first command. this will then e-mail me whenever a file is deleted. any help on how to do this...or even if you know a better way i would appreciate. thanks.

david_ross 10-10-2003 01:01 PM

To save running 2 find commands try:
Code:

#!/bin/bash

echo "Starting new cleanup "`date` > /tmp/cleanup.log

IFS="
"
for file in `find /home/lacey/test/cleanup/ -cmin -15 -type f`; do
echo $file
echo $file >> /tmp/cleanup.log
rm -f $file
done

cat /tmp/cleanup.log | mail root -s Cleanup log
rm -f /tmp/cleanup.log


wedgeworth 10-10-2003 01:35 PM

[root@localhost test]# ./test2.sh
/home/lacey/test/cleanup/test8
/home/lacey/test/cleanup/test9
[root@localhost test]# log... User unknown
......




this is what happens when i run the above script. i type "./test2.sh" and this is what happens. it just sits there and waits for me to hit return or something. anyway it is echoing correctly as you can see and it also e-mails me correclty i just don't know why it is doing the log....user unknown and then just hanging there. maybe it is b/c of IFS....which i have no background with and have no idea what it is doing. or is it from the log command at the end of cat command that is pipped to mail.?

david_ross 10-10-2003 02:38 PM

I think it is seeing log as an extra argument try replacing the line with:
cat /tmp/cleanup.log | mail root -s "Cleanup log"


All times are GMT -5. The time now is 04:56 PM.