Skip to main content
Question

mountNetworkShare.sh Question

  • January 14, 2014
  • 9 replies
  • 42 views

Forum|alt.badge.img+16

I have a bit of a peculiar situation regarding how to mount our users home shares. We have a bit of an odd setup where there is no data passed with the SMBhome field from AD. Our windows machines have a rather extensive login script that maps various drives based on group membership. I've been slowly replicating this in the JSS, for most shares I haven't had a problem. I am having an issue with mounting the users home directories. In this example for this group all the users are stored at a share that looks like the following.

smb://xxxx.xxx.xx.edu/akaltsas$

They are on on a file server, directly off the SAN, with hidden directories at the root of the share. If only we used ABE this wouldn't be an issue. Just mount the share, and they only see the directories they have access to. I've asked and there is no chance we will migrate to using ABE instead of these hidden directories. The networking team is pretty entrenched in using hidden directories.

I've been trying to modify the mountNetworkShare.sh script to poll the username and append the $ for the hidden share with little success. I'm sure it's just an issue of syntax, but i'm not sure. I thought if I put the shareUsername variable in quotes it would expand the variable and then just put the $ after the fact, but it's obviously not that easy. I will note that if I hardcode a username$ into the share variable the drive does mount fine. I'm sure I'm missing some easy way to insert the username variable into the share string but I'm at a loss as to what it is. Here is a sample of the modification I've made to the mountNetworkShare script

# HARDCODED VALUES SET HERE
shareUsername="$3"    #The username of the user to be used to mount the share - leaving this to $3 will mount the share as the currently logged in user
authType="kerberos"   #Valid values are "kerberos" (default) or "password"
password=""           #Note this only needs to be set if authentication type is "password"
mountType="smb"       #The type of file share. Valid types are "afp", "smb", or "dfs".  DFS only supports the "kerberos" authentication method
share='smb://xxxx.xxx.xx.edu/"shareUsername"$'          #The address of the share you are mounting - if left blank, the script will search for the "SMBHome" attribute in the user record

This is an example of what the script looks like for the AD bound Windows machines.

IF INGROUP("xxxx-Users")
    USE H: "\\xxxx.xxx.xx.edu" + @USERID + "$"

9 replies

Forum|alt.badge.img+13
  • Valued Contributor
  • January 14, 2014
share='smb://xxxx.xxx.xx.edu/$shareUsername$'

You weren't indicating that shareUsername was a variable (leading $)

Edited because I made a boo boo. It was ironic, you should have seen it.


Forum|alt.badge.img+13
  • Valued Contributor
  • January 14, 2014

In the category of teaching a man to fish, instrument your scripts with something like an echo to see what your variable looks like before you attempt to use it. You can leave these in most of the time, and when you get error logs back from policies, you'll see why.


Forum|alt.badge.img+13
  • Contributor
  • January 14, 2014

couple of items on your SMB link:

You want the $shareUsername in double quotes, even better also with curly brackets. you may need to escape the last $. Thus:

[code]share='smb://xxxx.xxx.xx.edu/"{$shareUsername}"$'[/code]


Forum|alt.badge.img+11
  • Contributor
  • January 14, 2014

http://tldp.org/LDP/abs/html/varsubn.html

Variable substitution does not occur within single quotes, only within double-quotes. Because of this, the enclosed variable, $shareUsername -or- ${shareUsername}, is not substituted by the value for shareUsername. You can test this with an echo command:

shareUsername=username
echo 'smb://xxxx.xxx.xx.edu/"$shareUsername"$'          #  smb://xxxx.xxx.xx.edu/"$shareUsername"$

However, because the $ character is special in bash, the trailing $ should be escaped if you use double-quotes instead. This doesn't appear to be needed, since it doesn't match a variable name it isn't expanded, but it's still best practice. Try this:

share="smb://xxxx.xxx.xx.edu/${shareUsername}$"

Forum|alt.badge.img+13
  • Valued Contributor
  • January 14, 2014

@justinrummel Your solution fails for me when I test as both a bash or sh script; did you try that on your end?

@Josh_S Your solution seems to work (either shell), but can you test what I posted above? I'm curious whether the note regarding variable substitution is actually true.


Forum|alt.badge.img+11
  • Contributor
  • January 14, 2014

Sure.

shareUsername='admin'
share='smb://xxxx.xxx.xx.edu/$shareUsername$'
echo $share        #  smb://xxxx.xxx.xx.edu/$shareUsername$

Forum|alt.badge.img+13
  • Valued Contributor
  • January 14, 2014

Okey dokey; chalk it up as another place where Darwin's bash != vanilla bash I guess.


Forum|alt.badge.img+16
  • Author
  • Valued Contributor
  • January 15, 2014

I appreciate all the help. I have made the modifications to the script and scoped it to the required group. The script appears to execute correctly and what appears to be a properly formatted file shows up in LaunchAgents. However the share never mounts. I can go into the launch agent file, copy out the SMB string, paste it into Go>Connect to Server and it mounts right up. So the kerberos ticket is valid. Any thoughts?

Executing Policy Mount xxxx-Users Home Directory...
Running script mountNetworkSharexxxxhome.sh...
Script exit code: 0
Script result: Volume name will be created as user$... Attempting to mount smb smb://xxxx.xxx.xx.edu/user$ using user's kerberos ticket... Writing out launch agent to /Users/user/Library/LaunchAgents/com.jamfsoftware.mapdrive.user$.plist Loading com.jamfsoftware.mapdrive.user$

Forum|alt.badge.img+16
  • Author
  • Valued Contributor
  • January 16, 2014

So I figured out that if I set the policy to Once per Computer the drive maps fine. Somehow the drive doesn't get mapped on the first run of the policy (script) where it writes the LaunchAgent. But subsequent authentications get the LaunchAgent triggered correctly. Is this the desired behavior of this script? When I go through the script it looks like it is designed to load the LaunchAgent after writing the LaunchAgent but it seems like that isn't happening.

Ideally I would like to remove the launch agent on logout so that the share's don't try to mount if our laptop users are away. But that won't be possible if I can only run this policy once per computer.

Thanks,

-alex-