[Samba] How to detect active users

Malte Forkel malte.forkel at berlin.de
Tue Jul 26 02:06:20 MDT 2011


Am 25.07.2011 23:34, schrieb Chris Weiss:
> On Mon, Jul 25, 2011 at 3:50 PM, Pascal Valois <pascal.valois at devinci.fr> wrote:
>> Le 25/07/11 22:44, Jeremy Allison a écrit :
>>>
>>> On Mon, Jul 25, 2011 at 10:21:35PM +0200, Malte Forkel wrote:
>>>>
>>>> Hi,
>>>>
>>>> I'm running Samba 3.2.5 on a server which I'd like to shut down when it
>>>> is not used by any client.
>>>>
>>>> Is there a way to detect whether any user has opened a file on the
>>>> server?
>>>
>>> smbstatus will tell you.
>>
>> slight correction,
>>
>> smbstatus tells you what file are used and by who, currently.
>> not who HAS opened a file.
> 
> smbstatus will also tell you who has an active connection to what
> shares, even if they have yet to actually open some file.
> 
> while it's possible for someone to open a file in app that reads to
> ram then closes, such as notepad.exe, making edits and letting them
> sit without saving for long enough that an smb client would disconnect
> the session is unlikely given the "save often" mentality that most
> have gotten from using PC's.  From application crashes, to power
> outages, to 2 year old kids pressing buttons, save often!

Thanks for your suggestions!

> so depending on what you mean by "has opened" (opened before and still
> use it, or opened before and may have close it), smbstatus may be the
> answer or not.

By "has opened" I mean "opened before and still use it". Actually,
something more like "would be disappointed if the server went down".
Ideally, a user might e.g. open a couple of source files to analyze them
and after a while (without making changes of saving anything) try to
open another file in the same directory.

I've done a couple of experiments with smbstatus, specifically its -S
and -L options. My clients run Windows 7 SP1 and Windows XP SP3. While a
Windows Expolores is opened for a share (or one of its subdirectories),
"smbstatus -S" will list that share. But once the Explorer is closed,
the entry is cleared. Similarly, using a File Open Dialog only produces
a short lived entry.

"smbstatus -L" does not seem to produce any list entries once a user has
opened a file. May be I have to specify some more specific locking in
smb.conf?

I've also experimented with "root preexec" and "root postexec". Those
seem to be triggered at the same time the output of "smbstatus -S" changes.

Currently, I'm not even sure Samba preserves the kind of state
information required to detect the usage scenario  I'm interested in. Is
there any concept of an "open file" in Windows/Samba, after all? May be
it depends on the application used to open the file?




More information about the samba mailing list