LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-10-2003, 01:29 PM   #1
wedgeworth
Member
 
Registered: Aug 2003
Posts: 234

Rep: Reputation: 30
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.

Last edited by wedgeworth; 10-10-2003 at 01:35 PM.
 
Old 10-10-2003, 02:01 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 66
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
 
Old 10-10-2003, 02:35 PM   #3
wedgeworth
Member
 
Registered: Aug 2003
Posts: 234

Original Poster
Rep: Reputation: 30
[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.?

Last edited by wedgeworth; 10-10-2003 at 02:39 PM.
 
Old 10-10-2003, 03:38 PM   #4
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Script: Find "Word" Run "Command" granatica Linux - Software 5 07-25-2007 08:42 AM
Several "find -exec" and "find | xargs" questions thanhvn Programming 4 12-02-2005 02:04 PM
Can't install "glibmm" library. "configure" script can't find "sigc++-2.0&q kornerr Linux - General 4 05-10-2005 03:32 PM
Where can I find the "make" & "cc" packages?? sayeed_ather Mandriva 2 04-28-2004 03:02 AM
"host" ok, but "ping" can't find ip address hardigunawan Linux - Networking 2 05-16-2002 06:41 PM


All times are GMT -5. The time now is 12:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration