Author Topic: Script that creates files/folders on samba drive fails  (Read 1293 times)

0 Members and 1 Guest are viewing this topic.

Offline orbikit

  • Jr. Member
  • **
  • Posts: 6
  • Karma: 0
  • I've just joined!
    • View Profile
    • Awards
Script that creates files/folders on samba drive fails
« on: March 08, 2017, 03:40:42 pm »
Bonjour,

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:
/run/user/1000/gvfs/smb-share:server=filehub,share=filehub_backups/Me/080317

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" - ??
« Last Edit: March 09, 2017, 09:38:53 am by orbikit »

Offline SeZo

  • Hero Member
  • *****
  • Posts: 1797
  • Karma: 136
  • Gender: Male
    • View Profile
    • Awards
Re: Script that creates files/folders on samba drive fails
« Reply #1 on: March 08, 2017, 09:01:52 pm »
You could try (replace script.sh with your script):
Code: [Select]
sudo bash script.sh

Offline orbikit

  • Jr. Member
  • **
  • Posts: 6
  • Karma: 0
  • I've just joined!
    • View Profile
    • Awards
Re: Script that creates files/folders on samba drive fails
« Reply #2 on: March 09, 2017, 09:30:21 am »
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 -??

Offline Mark Greaves (PCNetSpec)

  • Administrator
  • Hero Member
  • *****
  • Posts: 16941
  • Karma: 427
  • Gender: Male
  • "-rw-rw-rw-" .. The Number Of The Beast
    • View Profile
    • PCNetSpec
    • Awards
Re: Script that creates files/folders on samba drive fails
« Reply #3 on: March 11, 2017, 12:55:52 am »
Are you using "sudo" in the script ?

what I mean is, if script.sh contains say
Code: [Select]
#!/bin/bash
nemo /
even if you run that script with
Code: [Select]
sudo ./script.sh
nemo will still open as a regular user

if on the other hand script.sh reads
Code: [Select]
#!/bin/bash
sudo nemo /
and you run it with
Code: [Select]
sudo ./script.sh
nemo will open with elevated privileges.

script.sh must also be set as exectutable
Code: [Select]
chmod +x script.sh
WARNING: You are logged into reality as 'root'
logging in as 'insane' is the only safe option.
pcnetspec.co.uk

Offline orbikit

  • Jr. Member
  • **
  • Posts: 6
  • Karma: 0
  • I've just joined!
    • View Profile
    • Awards
Re: Script that creates files/folders on samba drive fails
« Reply #4 on: March 13, 2017, 02:30:27 pm »
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
exit

Ran thus:

roger@roger-HP-ProDesk-600-G2-SFF:~$ sudo /media/roger/Data/Scripts/CreateZIPBackups.sh
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 same[/i ]Terminal with SUDO??  (I am system admin incidentally).





Offline orbikit

  • Jr. Member
  • **
  • Posts: 6
  • Karma: 0
  • I've just joined!
    • View Profile
    • Awards
Re: Script that creates files/folders on samba drive fails
« Reply #5 on: March 14, 2017, 03:03:49 pm »
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??


Offline Mark Greaves (PCNetSpec)

  • Administrator
  • Hero Member
  • *****
  • Posts: 16941
  • Karma: 427
  • Gender: Male
  • "-rw-rw-rw-" .. The Number Of The Beast
    • View Profile
    • PCNetSpec
    • Awards
Re: Script that creates files/folders on samba drive fails
« Reply #6 on: March 14, 2017, 06:46:43 pm »
What's the output from:
Code: [Select]
ls -l /run/user/1000
I'm going to guess that only roger has write permission for the
/run/user/1000/gvfs/smb-share:server=filehub,share=filehub_backups
directory.

So the script needs to be run as roger, or the directory permissions changed as it's mounted
« Last Edit: March 14, 2017, 06:48:53 pm by Mark Greaves (PCNetSpec) »
WARNING: You are logged into reality as 'root'
logging in as 'insane' is the only safe option.
pcnetspec.co.uk

Offline orbikit

  • Jr. Member
  • **
  • Posts: 6
  • Karma: 0
  • I've just joined!
    • View Profile
    • Awards
Re: Script that creates files/folders on samba drive fails
« Reply #7 on: March 15, 2017, 04:01:04 pm »
Output:

-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 upstart-dbus-bridge.1644.pid
-rw-r--r-- 1 roger roger   5 Mar 15 07:05 upstart-file-bridge.1644.pid
-rw-r--r-- 1 roger roger   5 Mar 15 07:05 upstart-udev-bridge.1644.pid

Luckily there is only user on this machine :)

Offline Mark Greaves (PCNetSpec)

  • Administrator
  • Hero Member
  • *****
  • Posts: 16941
  • Karma: 427
  • Gender: Male
  • "-rw-rw-rw-" .. The Number Of The Beast
    • View Profile
    • PCNetSpec
    • Awards
Re: Script that creates files/folders on samba drive fails
« Reply #8 on: March 16, 2017, 07:39:56 pm »
well nobody other than roger has permission to read/write/execute the gvfs folder .. so your script must be run as roger, not root.
WARNING: You are logged into reality as 'root'
logging in as 'insane' is the only safe option.
pcnetspec.co.uk

Offline orbikit

  • Jr. Member
  • **
  • Posts: 6
  • Karma: 0
  • I've just joined!
    • View Profile
    • Awards
Re: Script that creates files/folders on samba drive fails
« Reply #9 on: March 22, 2017, 11:22:03 am »
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...

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal