Is there some sort of script I can write that logs usernames
every time someone (other than owner) "cd's into my pub directory"?

any ideas?

thanks

(I'm assuming Linux here)
You can write code to get notifications when there are modifications to a directory but I don't know of a way to get notifications when someone enters it. Though, what would be the point? If you are concerned with those who saw what was in there you'd also need to be notified on other situations ( ls -l comes to mind).
Even if you modified cd itself to do the logging, what happens in other situations like pushd , or ln -s to that directory?

What is it you really want to accomplish?

> I don't know of a way to get notifications when someone enters it

Monitor the parent directory. Entering the target directory modifies atime, so watching for IN_ATTRIB pretty much accomplishes the task.

PS: of course, nobody knows who did the access...

Edited 5 Years Ago by nezachem: n/a

Monitor the parent directory. Entering the target directory modifies atime, so watching for IN_ATTRIB pretty much accomplishes the task.

Is there some facility that does this for you - as in you can request asynchronous notification - or are you suggesting a hand-rolled solution? F_NOTIFY has DN_ACCESS and DN_ATTRIB but they dont seem to work for me on just cd into the directory (or subdirectory). I'd be interested in what you are suggesting.

F_NOTIFY is a dnotify feature. I referred to inotify.

PS: I have to admit, I didn't test it myself; let me try it as soon as I get to a linux box.

OK, I did the tests.

Of course entering the directory with cd does nothing (and I was wrong claiming otherwise). Only a default path of the process is changed.

On the other hand, any access (like ls ) does change the atime , which is immediately noticed.

Edited 5 Years Ago by nezachem: n/a

Try Dtrace. You shoudl be able to add some hook into kernel to monitor directory access and log if the directory in question == xyz.
Only port for linux I saw was from CRiSP available here.
Check status.txt for compatibility with your OS/version.

If you can make it run, then attached example (downloaded from here) can help you find how to write a script that will do what you want.

HTH

Attachments
This article has been dead for over six months. Start a new discussion instead.