Skip to main content

I am trying to mount a users network home directory using the "mountNetworkShare.sh" script located in the Scripts repository:



https://jamfnation.jamfsoftware.com/viewProductFile.html?id=135&fid=476



The script returns the following result when looking up the SMBHome from Active Directory:



\\dkhm0881xdrive3DKSXXXXXXXDocuments


However when the script attempts to mount the network location, it truncates simply to:



\\dkhm0881


I'm guessing that "x" is causing the script to prematurely escape, but I am not versed enough on scripting to find a solution to this one on my own. Has anyone else here experienced this issue or could propose a potential solution?

I think the mountnetworkshare script is designed to mount shares at static URLs. It doesn't know how to take that AD attribute that defines the user's home folder location and turn it into share path. You'll see in the first few lines of the script that there's an area to define the explicit share path to mount. The path must be defined there, and you'd have to write a different script for each person who you want to mount a share for; Does the built in AD bind not mount the share properly at login?


From what I can read, the script is setup to allow the administrator to pass values from the policy or use the default hard coded values set within the script:



####################################################################################################
#
# DEFINE VARIABLES & READ IN PARAMETERS
#
####################################################################################################

# 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='' #The address of the share you are mounting - if left blank, the script will search for the "SMBHome" attribute in the user record
#Example Values:
#SMB Share: smb://server.company.com/share
#AFP Share: afp://server.company.com/share
#DFS Path: \\server.company.comdfsroot arget


Based on these default values the script should dynamically use the SMBhome value from Active Directory for the currently logged in user. This step is accomplished later in the script:



#If the share parameter is blank, try to read the SMBHome attribute (home directory) from the LDAP server
echo "Attempting to read SMBHome attribute from user record since the 'share' parameter is blank..."
share=`/usr/bin/dscl /Search read /Users/$loginUsername SMBHome | head -1 | awk '{print $2}'`


A way to test the value being assigned to the variable share would be to write it this way and execute it directly in Terminal while logged in as the target user:



/usr/bin/dscl /Search read /Users/[user_name_here] SMBHome | head -1 | awk '{print $2}'


In my example, the resulting output is:



dkhm0881xdriveDKSXXXXXXXDocuments


Somewhere later in the script this output should be converted into:



smb://dkhm0881/xdrive/DKSXXXXXXX/Documents


However it's being truncated to:



smb://dkhm0881


Which I suspect is due to "x" being in the path name and causing it to escape prematurely. This is the portion I am looking for guidance on resolving as I am not as versed in script writing as I can be reading them somedays.


Follow up on this topic:



I ultimately ended up using a variation of this AppleScript from @bentoms, removing the portions for setting up printers and checking for and mounting network volumes based on Active Directory group memberships:



http://macmule.com/2011/09/08/how-to-map-drives-printers-based-on-ad-group-membership-on-osx/



From there I saved it as an application, created a package to deploy it to /Applications/Utilities/, then setup a policy to do the actual installation on all my managed clients.



Instead of creating a LaunchAgent and deploying it directly to the managed client, I was able to employ a User Level Configuration Profile with a Login Item payload.



Since this is a Non-Apple application however, I could not select it directly when creating the Configuration Profile in the JSS. Instead I had to:



• Create the Configuration Profile and select Activity Monitor.app in the payload.
• Download the Configuration Profile to my Desktop.
• Open the Configuration Profile in Xcode (or any other text editor).
• Update the path to the application in the Path key (and clean up the XML a bit).
• Delete the Configuration Profile from the JSS.
• Upload the modified Configuration Profile to the JSS.



It's worth noting that when you view the Login Item payload for the uploaded Configuration Profile, it will appear in the JSS as though no items are actually set to be launched.



However, downloading the Configuration Profile and opening it in Xcode will confirm otherwise.



For example:



<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1">
<dict>
<key>PayloadUUID</key>
<string>84419CAD-C4F8-4AF2-A46B-F76834AAEA47</string>
<key>PayloadType</key>
<string>Configuration</string>
<key>PayloadOrganization</key>
<string>YOUR_COMPANY_HERE</string>
<key>PayloadIdentifier</key>
<string>XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX</string>
<key>PayloadDisplayName</key>
<string>PAYLOAD_NAME_HERE</string>
<key>PayloadDescription</key>
<string/>
<key>PayloadVersion</key>
<integer>1</integer>
<key>PayloadEnabled</key>
<true/>
<key>PayloadRemovalDisallowed</key>
<true/>
<key>PayloadScope</key>
<string>User</string>
<key>PayloadContent</key>
<array>
<dict>
<key>PayloadUUID</key>
<string>XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX</string>
<key>PayloadType</key>
<string>com.apple.loginitems.managed</string>
<key>PayloadOrganization</key>
<string>YOUR_COMPANY_HERE</string>
<key>PayloadIdentifier</key>
<string>XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX</string>
<key>PayloadDisplayName</key>
<string>Login Items: Managed Items</string>
<key>PayloadDescription</key>
<string/>
<key>PayloadVersion</key>
<integer>1</integer>
<key>PayloadEnabled</key>
<true/>
<key>AutoLaunchedApplicationDictionary-managed</key>
<array>
<dict>
<key>Hide</key>
<true/>
<key>Path</key>
<string>/PATH/TO/YOUR/APPLICATION.app</string>
</dict>
</array>
</dict>
<dict>
<key>PayloadUUID</key>
<string>XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX</string>
<key>PayloadType</key>
<string>com.apple.loginwindow</string>
<key>PayloadOrganization</key>
<string>YOUR_COMPANY_HERE</string>
<key>PayloadIdentifier</key>
<string>XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX</string>
<key>PayloadDisplayName</key>
<string>Login Window</string>
<key>PayloadDescription</key>
<string/>
<key>PayloadVersion</key>
<integer>1</integer>
<key>PayloadEnabled</key>
<true/>
<key>DisableLoginItemsSuppression</key>
<false/>
</dict>
</array>
</dict>
</plist>