Skip to main content
Solved

Mount smb with a script

  • May 22, 2016
  • 3 replies
  • 113 views

Forum|alt.badge.img+7

Hello Community,

since a few hours I try to create a little script to mount a smb share. Before the script mount the share he check it. If it is not mounted he mount it.

It works ok... Now I have a few permissions problem...

The Script create a folder called "Intranet", then he mount it. It works but I can't see the Intranet because the folder get the wrong permissions. The folder get the permissions root:wheel but I need "User":admin or "User":"Domain Group

Via Terminal I can see all files as root... My question, how I can change the permissions to the corretcly?

Here is the actuelly script:

#!/bin/bash
# Already mounted check
user=`ls -la /dev/console | cut -d " " -f 4`
isMounted=`mount | grep -c "/Volumes/Intranet"`

if [ $isMounted -ne 0 ] ; then
    exit 0
fi
# Mount the network home
    mkdir /Volumes/Intranet
    sudo mount_smbfs //xxxx.xxxx/xxx/Intranet/Intranet/ /Volumes/Intranet
#   end tell
# Script End
exit 0

I hope erveryone can help..

Many Thanks!
Christian

Best answer by ds_support

Hello again!

I fixed the permission issue!

I forgot this "sudo -u $user" for the commands...

#!/bin/sh
    sudo -u $user mkdir /Volumes/Intranet
    sudo -u $user  mount_smbfs //xxxx.xxxx/xxx/Intranet/Intranet/ /Volumes/Intranet

now it works!

3 replies

Forum|alt.badge.img+7
  • Author
  • Contributor
  • Answer
  • May 22, 2016

Hello again!

I fixed the permission issue!

I forgot this "sudo -u $user" for the commands...

#!/bin/sh
    sudo -u $user mkdir /Volumes/Intranet
    sudo -u $user  mount_smbfs //xxxx.xxxx/xxx/Intranet/Intranet/ /Volumes/Intranet

now it works!


Forum|alt.badge.img+5
  • Contributor
  • July 25, 2016

I was just struggling with the same thing, and wanted to let you know that you helped me fix it. Thanks mate!


Forum|alt.badge.img+16
  • Valued Contributor
  • July 25, 2016

If you make a call to the Finder to do it instead the system generally takes care of pretty much all of it for you as the currently logged in user, the protocol is just included in the path and then permissions, mount points, cleaning up on eject etc... all just get dealt with by the system.

osascript<<END
tell application "Finder"
mount volume "$Share_Path"
end tell
END
}

Share_Path would be something like smb://server.domain/share