LinuxMuse.com Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   
Log in to check your private messagesLog in to check your private messages
   Log inLog in 

file filtering

 
Post new topic   Reply to topic    LinuxMuse.com Forum Index -> Software
View previous topic :: View next topic  
Author Message
hartingm



Joined: 29 Apr 2002
Posts: 36
Location: Tulsa, OK

PostPosted: Wed Nov 30, 2005 4:49 pm    Post subject: file filtering Reply with quote

I am setting up a clean up process on our system to remove temporary files that a report application creates. So far I have:

find /home/tempuser/report -amin +60 -iname *.txt

This gets me the initial list of files to look at. I need to filter that list to only files that have "TEMP" as the second line in the file. I am stuck at this point. I have tried using grep, but have not gotten it working correct yet.

Thanks for any ideas or suggestions.

Matt

p.s. This is being processed on a Slackware 10.1 system.
Back to top
View user's profile Send private message Visit poster's website
bilbrey
Muse Root


Joined: 04 Apr 2002
Posts: 210
Location: Sunnyvale, CA, USA

PostPosted: Sun Dec 04, 2005 12:46 pm    Post subject: Here you go, I think... Reply with quote

Hmmm. Okay, so the -amin +60 says only examine TEMP -containing files more that 60 minutes old. That I got. Then how about this:

create a shellscript called step2.sh (or whatever) and make it executable:

#!/bin/bash
TARGET=$1
head -n2 $TARGET | tail -n 1 | grep TEMP >> /dev/null
if [ $? == 0 ] ; then
echo $TARGET ;
fi

Then run this command in your cronjob:

find /home/tempuser/report -amin +60 -iname "*.txt" \
-exec /path/to/step2.sh {} \;

Once you're happy that it's always picking out the right files, then change that "echo $TARGET ;" line in step2.sh to "rm -f $TARGET ;"

best,

.brian
Back to top
View user's profile Send private message Visit poster's website
hartingm



Joined: 29 Apr 2002
Posts: 36
Location: Tulsa, OK

PostPosted: Mon Dec 05, 2005 3:19 pm    Post subject: Reply with quote

Brian,

Thanks for the help. That does exactly what I needed and I was even able to research and understand all of it. Very Happy

Matt
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    LinuxMuse.com Forum Index -> Software All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001 phpBB Group

RedHat Linux mod_gzip Apache mysql PHP

Linux is a registered trademark of Linus Torvalds. Linux systems contain a large component of GNU Software, see www.gnu.org for details.

All other brand and product names are or may be trademarks of, and are used to identify the products and services of their respective owners.

All other content Copyright (C) 2002 Linux Muse.

Other Legal Stuff ... Privacy Statement