Programmatically toggle smb shares

cub1t

Dabbler
Joined
Dec 9, 2020
Messages
10
Howdy.

If I do something ugly like a while loop that greps for the share name and toggle the smb share a few times I can discover that the general gist is along the lines of:

Code:
share_name=baz_share

## disable share
net --json conf showshare "$share_name"
net --json conf setparm <JSON_DATA>
smbcontrol smbd close-share "$share_name"
net conf delshare "$share_name"

## enable share
net --json conf showshare "$share_name"
net --json conf addshare <JSON_DATA>


However, if you try to call `net --json conf showshare` when the share has been disabled, it returns SBC_ERR_NO_SUCH_SERVICE.

I suppose I can store the returned json data from `showshare` to be used later for the `addshare`.

Does anyone have tips for how I might automate the enabling and disabling of samba shares?
(My specific use case is when mounting my pool over SSH, the shares must be toggled in the webgui before files are accessible to clients.)
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
midclt call sharing.smb.query | jq

Note the ID of your desired share, then use that like this:

midclt call sharing.smb.update 1 '{"enabled" : false }'

midclt call sharing.smb.update 1 '{"enabled" : true }'
 

cub1t

Dabbler
Joined
Dec 9, 2020
Messages
10
midclt call sharing.smb.query | jq

Note the ID of your desired share, then use that like this:

midclt call sharing.smb.update 1 '{"enabled" : false }'

midclt call sharing.smb.update 1 '{"enabled" : true }'
Thank you very much!
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
You can also add | jq to the end of the share changes to get the output in more readable form if that helps.
 
Top