Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to monitor an NFS share and detect the creation of a file by a process running on a remote system. The problem is that the detection isn't working after the file has been created, my script still thinks there's no file. If someone performs an ls in the directory, or I run a separate process that just does ls periodically in the background, the script will THEN detect that the file exists. Adding the "ls the directory" feature into the main script doesn't work, though: it still never picks up the existence of the file until an external process causes the directory list contents to be refreshed, somewhere somehow.

Here's a test case that illustrates the problem:

watch_file.pl:

#!/usr/bin/perl -w
my @stat;
while (1) {
    @stat = stat("/nfs/test");
    last if ($stat[1] && $stat[1] > 0);
}

Run that simple script on "host-A":

host-A% ./watch_file.pl &
[1] 9312

Move over to "host-B" and create the file:

host-B% touch /nfs/test

...back over to "host-A", program hasn't exited yet:

host-A% 

...still on "host-A", do an ls in the directory, then the script sees the file:

host-A% ls -a /nfs
.  ..  test
host-A%
[1]+  Done                    ./watch_file.pl &
host-A%

Does anyone know of a simple fix or workaround for this that would be less hokey than running a script in the background to ls the NFS directory every 10 seconds?

share|improve this question
    
Maybe this should be on stackoverflow? –  Server Horror Jun 8 '11 at 17:01
    
Probably right... pardon the noob who is just learning the ins and outs of these great sites. –  Daniel DeVoe Jun 8 '11 at 17:45
1  
Not to worry, some moderator will probably move it "real soon now" - it'll still show up here so you can even keep you bookmark :) –  Server Horror Jun 8 '11 at 18:28

1 Answer 1

up vote 1 down vote accepted

By default, most NFS clients cache directory information for 60 seconds.

Mount the NFS share on the client with the noac option to disable attribute caching, or use acdirmin=0,acdirmax=0 to just disable directory caching.

share|improve this answer
    
Perfection! I'm indebted Hyppy and would upvote you if I had the rep. –  Daniel DeVoe Jun 8 '11 at 17:16
    
@Daniel No upvote needed, but an "accept" would be appreciated. (The checkmark under the vote count) –  Hyppy Jun 8 '11 at 17:21
1  
Done and done. Thanks for being so patient with me! –  Daniel DeVoe Jun 8 '11 at 17:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.