[Solved] Shell script to read-only share Public folder.

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
SilverNexus

[Solved] Shell script to read-only share Public folder.

Post by SilverNexus »

I know that folders can be shared over the network easily from a GUI, but I want to run a computer with no monitor (hence GUIs are useless) and still have the Public folder be shared. However, since the shared folder settings refuse to persist on reboot (maybe I'm missing something that does that, I have been uninstalling a lot of packages from the computer), I was hoping to have a startup script that set up the shared folder by itself.

I'm guessing this would involve Samba somewhere, but I have no clue where to start, or how complex a task this would even be. A nudge in the right direction, at minimum, would be greatly appreciated.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
altair4
Level 20
Level 20
Posts: 11427
Joined: Tue Feb 03, 2009 10:27 am

Re: Shell script to read-only share Public folder.

Post by altair4 »

That is a very confusing post since if you already shared the Public folder ( forget for a moment that it does not persist a reboot ) then you are already using Samba.:
However, since the shared folder settings refuse to persist on reboot
I'm guessing this would involve Samba somewhere, but I have no clue where to start, or how complex a task this would even be.
For starters I would run the following commands the next time you boot:

This one will tell you if the share definition still exists:

Code: Select all

net usershare info --long
These will tell you if the samba services are running:

Code: Select all

sudo service smbd status
sudo service nmbd status
Anywho, you can create a samba share from the terminal using this syntax:

Code: Select all

net usershare add Public /home/altair/Public "" Everyone:R guest_ok=y
Change:
altair to your own user name.
Everyone:R to Everyone:F is you want all clients to have write access
guest_ok=yes to guest_ok=no if you want to restrict access only to users in the samba password database.

The thing is though this shouldn't be disappearing between boots so if there is something severely broken with your set up you can do this the traditional way by adding a Classic Samba share to /etc/samba/smb.conf:

Code: Select all

[Public]
path = /home/altair/Public
read only = yes
guest ok = Yes
Then restart samba:

Code: Select all

sudo service smbd restart
Change:
read only = yes to read only = no if you want write access
guest ok = Yes to guest ok = No is you want to restrict access.

EDIT: If you run into any problems post the output of these two commands:

Code: Select all

testparm -s

Code: Select all

net usershare info --long
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
SilverNexus

Re: Shell script to read-only share Public folder.

Post by SilverNexus »

altair4 wrote:That is a very confusing post...
Yeah, that probably wasn't the best wording. What I meant was that I already had samba, but had no idea what the shell commands to do this were. It could have been one line, or it could have been 100.
However, thanks to your help. this is no longer the case.

"net usershare info --long" yielded no output, so I assumed that this meant there were no active shares. I proceeded to look at /etc/samba/smb.conf, and saw that the share from last boot was there, but was not active. So, I ran the "net usershare add Public /home/SilverNexus/Public "" Everyone:R guest_ok=y" and it worked, since net usershare info --long gave the share information now. I'll just add that line to my /etc/rc.local and go with it from there.

Again, I thank you for your help.
altair4
Level 20
Level 20
Posts: 11427
Joined: Tue Feb 03, 2009 10:27 am

Re: [Solved] Shell script to read-only share Public folder.

Post by altair4 »

Note: the only reason I'm posting this is just in case someone comes across this topic and thinks that what you are doing is required for anyone else.

I'm not sure I understand what you meant by "I proceeded to look at /etc/samba/smb.conf, and saw that the share from last boot was there, but was not active." but once you use the "net usershare add" command a share definition file is permanently created at /var/lib/samba/usershares. There is no need to keep adding it through rc.local. In fact it should fail since the share definition already exists.

Something is still amiss with your system if you need to recreate it at every boot.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
SilverNexus

Re: [Solved] Shell script to read-only share Public folder.

Post by SilverNexus »

altair4 wrote:I'm not sure I understand what you meant by "I proceeded to look at /etc/samba/smb.conf, and saw that the share from last boot was there, but was not active."
What I mean is, the last share I made was at the end of /etc/samba/smb.conf, but the output (or lack thereof) of "net usershare info --long" indicated that there were no active shares.

I really should have been more specific.

As for the state of the system, this seems to work, even if it shouldn't have to be manually reenabled on bootup. I'd prefer to not break what "works" as of now trying to reach that supposed functionality.

I remember coming across a post (written by you, altair4) from 18 June 2009 about a bug in nautilus-user-share that caused it to not persist share definitions of predefined folders. Perhaps this is that bug (or leftovers from it, assuming it was fixed) cropping up in MATE.
[url]http://forums.linuxmint.com/viewtopic.php?f=42&t=23169&p=135786[/url]
Then again, this could be its own entity in itself.
altair4
Level 20
Level 20
Posts: 11427
Joined: Tue Feb 03, 2009 10:27 am

Re: [Solved] Shell script to read-only share Public folder.

Post by altair4 »

You can create samba shares 2 different ways:

Through smb.conf
And through the File Manager which creates a samba usershare.

Based on your original post I assumed you did it through the file manager which is why I asked you to see if "net usershare info --long" showed the share. If I had known you had a share already defined in smb.conf I wouldn't have asked for it.

** The share in smb.conf should work - I can't think of a mechanism which would make it not work.
** It wasn't necessary to create it via the usershare command.
** And it's certainly not required to do it more than once.
I remember coming across a post (written by you, altair4) from 18 June 2009 about a bug in nautilus-user-share that caused it to not persist share definitions of predefined folders. Perhaps this is that bug (or leftovers from it, assuming it was fixed) cropping up in MATE.
http://forums.linuxmint.com/viewtopic.php?f=42&t=23169&p=135786
I never said the "sharing" of the file didn't persist I said this:
Please note that there a series of 3 bugs in the way nautilus "reports" the state of the share using this method. It does not impact the actual share status, they are only bugs in the way nautilus displays the state of the share:
When a folder is shared through Nautilus ( Nemo ) it changes the emblem on the folder to indicate that it was shared. There was a bug ( it may still be there ) where after a reboot the emblem changes back to it not being shared - but that is cosmetic only - the folder is still shared.

I understand you unwillingness to mess about with things as you have a method around whatever is wrong with your system.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.
SilverNexus

Re: [Solved] Shell script to read-only share Public folder.

Post by SilverNexus »

altair4 wrote:I never said the "sharing" of the file didn't persist I said this:
Hmm... must have read it too fast. :lol:
I guess I have no rationale for why user shares refuse to persist, since it also happens on my 64-bit install which I did not strip of numerous packages.
At least there's an easy workaround.
SilverNexus

Re: [Solved] Shell script to read-only share Public folder.

Post by SilverNexus »

Oddly enough, installing caja-share (yes, I'm using MATE) made the usershare persist. I don't know why that has any affect on actual sharing, but it seems to.
Locked

Return to “Scripts & Bash”