Script that creates files/folders on samba drive fails


I have modified a very simplistic script I was using to create folder/file backups as ZIP files onto a local drive too using the address of a Samba drive:

Which is a share on a Windows 7 Professional machine.

However, if I go to that location in the Terminal I can create files/folders no issue. If I run the script every command returns “permission denied”.

Steps taken:

  • made sure script had execute permissions (tried 0750 and 0777)
  • always ran script using SUDO
  • checked smb.conf had RW permissions
  • created test script with same permissions that just accessed the Samba folder using CD (same error message)

At the moment I am at a loss as to how in Terminal using SUDO I can read/write but using a script run in Terminal as SUDO it just returns “permission denied”

Here is a bit of the script:

VARFOLDER=$(date +%d%m%y)
mkdir /run/user/1000/gvfs/smb-share:server=filehub,share=filehub_backups/Me/$VARFOLDER

If I copy that and replace $VARFOLDER with anything else and paste it into Terminal it works, but running the script with SUDO returns “permission denied” - ??

You could try (replace with your script):

sudo bash

that is exactly what I am doing but every line returns: “permission denied”
if I type the same commands directly into the Terminal it works -??

Are you using “sudo” in the script ?

what I mean is, if contains say

nemo /

even if you run that script with

sudo ./

nemo will still open as a regular user

if on the other hand reads

sudo nemo /

and you run it with

sudo ./

nemo will open with elevated privileges. must also be set as exectutable

chmod +x

Done that!

The script has execute rights,

Changed the script to this:

VARFOLDER=$(date +%d%m%y)

#mkdir /run/user/1000/gvfs/smb-share:server=filehub,share=filehub_backups/Me/$VARFOLDER
sudo mkdir /run/user/1000/gvfs/smb-share:server=filehub,share=filehub_backups/Me/$VARFOLDER

Ran thus:

roger@roger-HP-ProDesk-600-G2-SFF:~$ sudo /media/roger/Data/Scripts/
mkdir: cannot create directory ‘/run/user/1000/gvfs/smb-share:server=filehub,share=filehub_backups/Me/130317’: Permission denied

Same result!

I can create the folder directly using the same code in the same Terminal session without having to use SUDO - no issues?

It is as though Terminal has more disk access rights than a script run in the [i]same[/i ]Terminal with SUDO?? (I am system admin incidentally).

I suspect it has something to do with Samba. The share has RW access yet despite the executing attribute of the script and running/filling it with SUDO it seems Ubuntu gives direct Terminal commands read/write access but not scripts??

What’s the output from:

ls -l /run/user/1000

I’m going to guess that only roger has write permission for the

So the script needs to be run as roger, or the directory permissions changed as it’s mounted


-rw-rw-r-- 1 roger roger 60 Mar 15 07:05 dbus-session
drwx------ 2 roger roger 60 Mar 15 15:52 dconf
dr-x------ 3 roger roger 0 Mar 15 07:05 gvfs
drwx------ 2 roger roger 40 Mar 15 10:18 gvfs-burn
drwx------ 2 roger roger 100 Mar 15 07:05 keyring
drwx------ 2 roger roger 80 Mar 15 10:24 ksocket-roger
drwx------ 2 roger roger 80 Mar 15 07:05 pulse
drwx------ 4 roger roger 100 Mar 15 08:28 speech-dispatcher
drwxr-xr-x 2 roger roger 80 Mar 15 07:05 systemd
drwx------ 2 roger roger 40 Mar 15 07:05 unity
drwx------ 3 roger roger 60 Mar 15 07:05 upstart
-rw-r–r-- 1 roger roger 5 Mar 15 07:05
-rw-r–r-- 1 roger roger 5 Mar 15 07:05
-rw-r–r-- 1 roger roger 5 Mar 15 07:05

Luckily there is only user on this machine :slight_smile:

well nobody other than roger has permission to read/write/execute the gvfs folder … so your script must be run as roger, not root.

roger is also a member of root.

Still does not explain why if I redirect the script to create the folder/files on any local drive it works, but not Samba shares…