Question

Locked

Housekeeping

By aloymark ·
I would like to write a script to housekeep large files that are not currently accessed/used and this script is to be put in cron. (These files are actually temporary and will be deleted once processing is complete. However, due to some application problem, the files are not removed, causing filesystem full)

I have the following files with k3file.001 & k4file.001 still processing (in use).

-rw-rw-rw- 1 amark sys 5984 Jan 4 20:03 k1file.001
-rwxrwxrwx 1 amark sys 229 Jan 4 20:04 k2file.001
-rwxrwxrwx 1 amark sys 416 Jan 4 20:08 k3file.001
-rwxrwxrwx 1 amark sys 416 Jan 4 20:08 k4file.001

How do I remove all the files except for k3file.001 & k4file.001? Please help.

This conversation is currently closed to new comments.

6 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

interactive option in rm

by john.a.wills In reply to Housekeeping

rm -i k?file.001 causes the user to be asked for each filename generated whether removal is desired.

Collapse -

The find command might do the trick for this

by DanLM In reply to Housekeeping

But, I have some questions first.

How do you know which files can and can not be deleted? Ok, you can list off files that are over a specific size and created after/before a time stamp using the find command. But, looking at your list of files. Their time stamp is only 4 seconds different from oldest to newest. You listed two files, you obviously know that where the problem is. How???


If you know what files the application creates(which I think you do), you could put a cron in that does something like this:

find /directory name -type f -name "k*file.001" -exec rm {} \;


This would delete all of the files that have those type file names. But if you know specific file names I could work up what the syntax should really be.

I use something like that actually in a crontab to look for core dump files and delete them. And thankfully, there are not always core dumps. lol

1 1 * * * find / -type f -name core -exec rm -f {}\; >/dev/null 2>&1

Also, you can mix and match your find criteria. Ie, I am looking for any file that has a name charachteristic of blabla*.bla1 with a size greater then 4k and created after jan 04 2007. That might be what your looking for.

Here is a link with a boat load of real life xamples of the find command.

http://www.wagoneers.com/UNIX/FIND/find-usage.html


Hope this helps.

Dan

Collapse -

Housekeeping

by aloymark In reply to The find command might do ...

Ok, put it this way.
Actually I have a cron which looks like this and I want it to be in script form as insisted by my superior (!@^?#):

00,10,20,30,40,50 * * * * touch /tmp/dummyfile

05,15,25,35,45,55 * * * * find /tmp -name 'k*file.001' ! -newer /tmp/dummyfile -exec rm {} \;

I've been trying to revise this command 'coz I'm sure there's other easier way of doing it but to no avail. Now, I want it to be in script form. Allowance is 10 mins approx. for file processing before they can be deleted.

I hope I describe it better now, or am I making it worse???

Collapse -

welllllllllllllllllllllllllllllllllll

by DanLM In reply to Housekeeping

The script with the above could look something like this with the commands you have.
script name ehhhh. monitor.sh
#!/bin/sh
touch /tmp/dummyfile
sleep 300
find /tmp -name 'k*file.001' ! -newer /tmp/dummyfile -exec rm {} \;


your contrab would look like this
*/10 * * * * {path to monitor.sh}/monitor.sh

This would launch your script every 10 minutes, and the sleep in the script would wait 5 minutes before doing the find command.

So, you are checking to see if the files (k*.001) have a last access date/time less then dummy. cool, would have never thought of doing this that way.

Does that help?

dan

by the way, thanks for showing me that find command. I never used/seen that option, but its something I can see me using.

Collapse -

ya know, I was thinking about this

by DanLM In reply to Housekeeping

You could make the script a daemon. lol, with the use of the sleep command and a different option of the find. You could check the last modification date/time stamp during any interval.

Ie, every 30 seconds. Is the last mod time of this file 5 minutes ago from the time this find was executed.

ie:

find /tmp -name 'k*file.001' -cmin 5 -exec rm {} \;
sleep 30

Then the find would execute every 30 seconds to check to see if the files were unaccessed in the last 5 minutes?

Is that more what your looking for?

Dan

Back to Software Forum
6 total posts (Page 1 of 1)  

Related Discussions

Related Forums