Network Share Mounting Problems - Share Names with spaces

SeanBurke
New Contributor

Hey guys,

This is my first JAMFNation post so bare with me and the enormous novel. I'm having an issue with mounting network shares, but not really in a traditional way. I'll explain a bit of background. Please tell me I'm over thinking this and that there's a really easy solution :)

What we'd like to have is users to log in and be able to see their own individual network share mounted on the desktop. Their individual network share with their name. One of our previous sysadmins set up our network shares.. not so well, so here is the structure and what we're trying to achieve:

The user's individual folders are located within a network share with a space in the name, let's call it: Users A. They log into domain bound macs with the username format: Firstname.Lastname, but their individual network shares were set up as FirstName<space>LastName (yeah, don't ask me why).

So say I'm accessing my individual network share, it would be smb://my.company.com/Users A/John Doe. If I mount this most traditional ways, it will only mount the Users A folder on the desktop instead of the John Doe folder straight to the desktop. I modified the mountNetworkShares.sh script and this is what happened. So if you do CMD + K and type in smb://my.company.com/Users%20A/John%20Doe/ you would get Users A on the desktop as well.

I wrote the following bash script which resolves the issue... sort of. I have a policy scoped for users that would be associated with the Users A and did an ongoing login policy that runs this bash script:

#!/bin/sh

name=$3
nameSpace=${name/./'%20'}
type=" -type smb"

jamf mount -server 'my.company.com/Users%20A/'$nameSpace$type

So the script takes in the $3 variable at login, which would be john.doe. The script then replaces the period with %20, resulting in john%20doe and leverages the jamf mount command (which I found will actually mount the individual's folder rather than the Users A folder) to mount the drive. This script runs perfectly if I'm logged in and run the command from the terminal. I review the error in the JSS and I see the following:

Script Result: Mounting smb://my.company.com/Users%20A/john%20doe/ to /Volumes/ 1...
There was an error mounting the file server smb://my.company.com/Users%20A/john%20doe/. Will attempt again.

As I said before, I ran this script while logged in and it worked perfectly. If I do a CMD + K and copy/paste: smb://my.company.com/Users%20A/john%20doe/ , it's able to mount (but like I said, it only mounts the Users A folder). If I do a jamf mount -server 'my.company.com/Users%20A/john%20doe/' -type smb, it's also able to mount the network share just fine. It's obviously getting the $3 variable at login and doing the correct operations to make it john%20doe, it's just reporting back an error and not actually mounting the drive.

Any insight would be greatly appreciated. Sorry again for the long novel, but I'm at a loss and figured I would put this out to the braintrust for alternate methods / ideas.

5 REPLIES 5

jamie_ivanov
New Contributor

Welcome to the JAMF Nation.

First, %20 is a URI modifier which is not used in non URI paths (like URLs, path URIs in Finder, Explorer, etc).

Second, you would need to "escape" the space with a backslash ("") or use quotes to have the shell escape it automatically.

Also, you can use $USER instead of $3 if you're working directly within a shell on the local system (finding the user of the currently logged on person who launched said shell). Using double-quotes will tell the shell to process the string in it's entirety.

#!/bin/sh
jamf mount -type smb -server "my.company.com/Users A/$USER"

or

#!/bin/sh
jamf mount -type smb -server "my.company.com/Users A/$USER"

I'm not sure if I accounted for all of your variables.

J.I.

frozenarse
Contributor II

Two quick questions:
1. Where are you getting the path that is being used?
2. What changes did you make to the mountnetworkshares.sh file?

I'm using that script and it results in the desktop object having the username listed. But if I look in /volumes via terminal... it is listed as the share.

recap:
My network path: //server/share$/staff/username
Results in: username shortcut on desktop and share$ listed in terminal under Volumes

I unfortunately don't have any accounts with spaces to test with.

SeanBurke
New Contributor

Hey Guys,

Thanks for the quick replies. jamie.ivanov - thanks for the reply about the escape character suggestion (though %20 actually does work via Go-> Connect to Server, - fun fact). I've tried what you mentioned and it's still not working. I get the following in my JSS

Script Result: Mounting smb://my.company.com/USER A/John Doe/ to /Volumes/ 1...
There was an error mounting the file server smb://my.company.com/USER A/John Doe/. Will attempt again.

From the script:

#!/bin/sh

name=$3
nameSpace=${name/./' '}
jamf mount -type smb -server 'my.company.com/USERS A/'"$nameSpace"

Tried another way with:

#!/bin/sh

name=$3
nameSpace=${name/./' '}
jamf mount -type smb -server "my.company.com/Users A/$nameSpace"

Results in:

Script Result: Mounting smb://my.company.com/Users A/john doe/ to /Volumes/ 1...
There was an error mounting the file server smb://my.company.com/Users A/john doe/. Will attempt again.

Frozenarse - Interesting, maybe it has to do with the spaces that's causing the network share not to mount to the desktop properly. I noticed the mountNetworkShares.sh produces an oascript call within the plist in the LaunchAgents - I believe the call was for the full path (my.company.com/Users A/john doe). I believe all I did was create another variable in the mountNetworkShares script that was something like nameSpace=${$3/./' '} then tacked it on to the end of the $share variable. Then for parameter 7 in the policy I'd use smb and paramater 8 would be my.company.com/Users A. So the mountNetworkShares script would take the my.company.com/Users A and tack on /John Doe to the end. Hopefully this makes sense - it did work but didn't mount John Doe, it mounted the Users A folder to the desktop.

Thanks again for all your help!

jamie_ivanov
New Contributor

1) Don't use the nameSpaces variable. Regex and paths don't always place nice. Using quotes eliminates the need for that.

2) I noticed something funny about the results you got. Can you provide the full output that includes the complete mount path?

3) Assigning $3 to 'name' is redundant. Just use $3 instead of 'name' a.

I'm sorry but I won't be at a terminal until later tonight or I could probably make a more concrete suggestion.

J.I.

frozenarse
Contributor II

Here is what i'm seeing in my policy log:

Share determined to be: smb://SERVERNAME/SHARENAME$/STAFFVISITORS/USERNAME.
Volume name will be created as USERNAME...

I searched the script from the resource kit and there is a section called "Determine a volume name based on the share". That appears to be where the value for 'volumeName' is set. volumeName is used later on in the 'Create a launch agent to mount the drives' section.