Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

#!/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% ./ &
[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:


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

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

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
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
up vote 5 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
Done and done. Thanks for being so patient with me! – Daniel DeVoe Jun 8 '11 at 17:42

Your Answer


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.