I have an Ubuntu-based HTPC running Samba (the server). Other PCs in the local network (the clients) connect to the Samba shares on the NAS and use them as network drives (all of those PCs run Win 7).
I'd like to have the server go to sleep when it's not being used in any way. I've successfully set up the clients to wake it when they connect to the local network; the thing that causes trouble is getting it to sleep. I need a way to reliably determine that none of the Samba shares are currently in use. I have tried using pre / post exec hooks in
smb.conf along with a custom script to keep track of the currently used shares, and that worked most of the time. Except for the case when the client is not shut down, but hibernated instead. When that happens, the post exec hook is never called. And that is a major problem, because half the clients on the local network are laptops.
I have since developed a simple cron job which is run every couple of minutes. It's task is to detect if anybody is using the server in any way (including mounted Samba shares); otherwise it puts the server to sleep. So far I've been parsing the output of
smbstatus -S, but that still shows the shares are in use, even after the client which is supposed to use them is hibernated and well off the network. Moreover, when I do a
netstat -tp | grep smbd at that moment, the connection to the offending client is present in the output, showing up as "ESTABLISHED", with the correct IP an' everything.
At this point I'm on the verge of grepping out the IPs of the clients from the
netstat output and pinging them, one by one, to check if the clients are really up and running :o/ I'd really like to avoid doing that, as the current solution is already pretty voodoo.
Please, if anybody has a clue what else can I do, any help would be greatly appreciated.