Operating System - HP-UX
1833283 Members
3156 Online
110051 Solutions
New Discussion

find option for not-open files?

 
SOLVED
Go to solution
Gordon  Morrison_1
Regular Advisor

find option for not-open files?

Hi,
My pesky users keep filling up /tmp (there are far too many to re-educate!).
They have kindly said that I can delete any files older than 10 days, but there are always some files in there which are being held open by processes.
fuser returns success if it runs successfully regardless of whether the file is open or not, and I could see no mention of detecting open files on the find man page.
I want to script a cron job to delete files older than 10 days, but exclude open files.
Any ideas?
What does this button do?
7 REPLIES 7
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: find option for not-open files?

You could feed the output of your find to an lsof command specifying +D /tmp. You also need to get your users to quit using /tmp. /tmp is for the operating system's temp files; users should be using /var/tmp.
If it ain't broke, I can fix that.
Victor BERRIDGE
Honored Contributor

Re: find option for not-open files?

Hi,
I suppose you will need lsof to see which files are opened by processes...
Ge and dowload it from your favorite Archive porting center

Good luck

All the best
Victor
Peter Godron
Honored Contributor

Re: find option for not-open files?

Gordon,
congrats on the headgear!
The long term fix would be to set quotas on the users, which would stop them leaving files lying around.
It's difficult to spot individual open files unless you use lsof. You could try combining the find option for creation date > 10 days and modification time < 1 day, but this depends on how often the files get written to.
I'm sure somebody will have a perl script.
Robert Bennett_3
Respected Contributor

Re: find option for not-open files?

#!/usr/bin/sh
# remove files in /tmp not modified in 10 days
find /tmp -mtime +10 -type f -exec rm {} \;

"All there is to thinking is seeing something noticeable which makes you see something you weren't noticing which makes you see something that isn't even visible." - Norman Maclean
Procnus
Frequent Advisor

Re: find option for not-open files?

The command line I generally use is:
fuser 2>/dev/null | grep [0-9] >/dev/null

$? becomes the return code for the grep

Cheers
Steven
Gordon  Morrison_1
Regular Advisor

Re: find option for not-open files?

Thanks for all your replies. My thoughts and/or test results for each are below:

Clay;
lsof looks like it will do the trick, thanks! Though I don't think I need the +D flag in this case (the man page was even harder to find than the binary!)
I know they shouldn't be doing it, but there are hundreds of them (clueless lusers, keyboard monkeys, cow-orkers, in-DUH-viduals, call 'em what you will) I'm outnumbered!

Victor; ditto on the lsof idea

Peter; (Aw, gee thanks!) Unfortunately, these users are all tippity-tappity-typing in LOADSAMONEY for The Company, so enforcing quotas is really not an option (never delete files, quota gets reached, can't create files, application hangs, money stops coming in, customers get P'd off, go elsewhere, "what happened?" "Well, Gordon set these quotas..." "Oh. I wish him luck in his next job.") Ditto for lsof, as these open files don't get written to for many days at a time and they belong to the main application for this box, that's why find -mtime doesn't cut it.

Robert; That's exactly the command I would normally use, but being paranoid, I ran it through fuser instead of rm, and found open files not written to for >10 days. Phew, that was close!

Steven; That looks good, and I really thought it would work, but as you can see from the output below, it returns inconsistent results and I have no idea why. It *should* have worked.

for file in *AH[DP]P
do
fuser $file
fuser $file 2>/dev/null | grep [0-9] >/dev/null
echo $?
done
B6161scrn.AHPP:

1
B6238scrn.AHPP:

1
CMD-R42054291832.AHPP:

1
REFUND_AHDP:

1
REFUND_AHPP:

1
bwdaemon.AHDP: 24746o

1
bwdaemon.AHPP: 24293o

1
clm_aud_07-FEB-05_AHDP:

1
clm_aud_07-FEB-05_AHPP:

1
clm_aud_08-FEB-05_AHDP:

1
clm_aud_08-FEB-05_AHPP:

1
clm_aud_09-FEB-05_AHDP:

1
clm_aud_09-FEB-05_AHPP:

1

etc. etc. etc.
blah blah blah...

clm_aud_20-FEB-05_AHDP:

1
clm_aud_20-FEB-05_AHPP:

1
clm_aud_21-FEB-05_AHDP:

1
clm_aud_21-FEB-05_AHPP:

1
pms_errAHDP:

1
pms_errAHPP:

1
qasdaemon.AHDP: 24741o 24747o

1
qasdaemon.AHPP: 10984o 11013o

0
strm_errAHDP:

1
strm_errAHPP:

1

========
Go figure :o/

Thanks again to all
What does this button do?
Gordon  Morrison_1
Regular Advisor

Re: find option for not-open files?

lsof is what I needed
What does this button do?