Mount smb with a script

ds_support
New Contributor III

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

1 ACCEPTED SOLUTION

ds_support
New Contributor III

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!

View solution in original post

3 REPLIES 3

ds_support
New Contributor III

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!

omatsei
New Contributor III

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

Look
Valued Contributor III

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