If your samba server is configured to use file locking which is probably is, I suppose you could use 'smbstatus -L' to list the locks and then grep the output for the type of lock you're looking for (EXCLUSIVE, BATCH) if you knew you only cared about certain kinds of locks.
Something like:
smbstatus -L | grep EXCLUSIVE
and then test against the return value ($?) in the cron job script.
Unfortunately, I don't know enough about the types of locks to know if this is a suitable catch-all method or not.
cense's answer is good, and his thing about the locks applies to this answer. Samba also allows read only status (I think it shows up as RD_ONLY), and also displays entries for directories that are open in Windows Explorer, so you have to decide what kind of locks you want to ignore/focus on.
I believe the output of smbstatus is No machines connected., if, well, no machines are connected, so you could possibly use something like smbstatus|grep No\ machines\ connected && shutdown to shutdown when nothing's connected.
To the best of my knowledge (No access to a Samba server right now), if you have a Samba share mounted in Windows, smbstatus will show that the Windows machine has connected, even if the user isn't actively using the share, so you'll probably need to decide what to do based on that case too.
If your samba server is configured to use file locking which is probably is, I suppose you could use 'smbstatus -L' to list the locks and then grep the output for the type of lock you're looking for (EXCLUSIVE, BATCH) if you knew you only cared about certain kinds of locks.
Something like:
smbstatus -L | grep EXCLUSIVE
and then test against the return value ($?) in the cron job script.
Unfortunately, I don't know enough about the types of locks to know if this is a suitable catch-all method or not.
I would probably use the lsof command to determine what files are in use on the share.
lsof | grep /path/to/share
should show files in use.cense's answer is good, and his thing about the locks applies to this answer. Samba also allows read only status (I think it shows up as RD_ONLY), and also displays entries for directories that are open in Windows Explorer, so you have to decide what kind of locks you want to ignore/focus on.
I believe the output of
smbstatus
isNo machines connected.
, if, well, no machines are connected, so you could possibly use something likesmbstatus|grep No\ machines\ connected && shutdown
to shutdown when nothing's connected.To the best of my knowledge (No access to a Samba server right now), if you have a Samba share mounted in Windows,
smbstatus
will show that the Windows machine has connected, even if the user isn't actively using the share, so you'll probably need to decide what to do based on that case too.