| View previous topic :: View next topic |
| Author |
Message |
hartingm
Joined: 29 Apr 2002 Posts: 36 Location: Tulsa, OK
|
Posted: Wed Nov 30, 2005 4:49 pm Post subject: file filtering |
|
|
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 |
|
 |
bilbrey Muse Root
Joined: 04 Apr 2002 Posts: 210 Location: Sunnyvale, CA, USA
|
Posted: Sun Dec 04, 2005 12:46 pm Post subject: Here you go, I think... |
|
|
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 |
|
 |
hartingm
Joined: 29 Apr 2002 Posts: 36 Location: Tulsa, OK
|
Posted: Mon Dec 05, 2005 3:19 pm Post subject: |
|
|
Brian,
Thanks for the help. That does exactly what I needed and I was even able to research and understand all of it.
Matt |
|
| Back to top |
|
 |
|