Hi everyone, we're trying to auto mount some SMB shares on user login using Jamf Policies but although I can get a script to work having a bit of trouble getting it to work in a user-specific way.
Our share target is dfsrootMacHomesuser1 (where user1 is the username of whoever logs in). We don't use Home Folders in our AD and don't want to modify it to add them in case of unexpected side-effects for our Windows machines so the standard Jamf behaviour where it auto mounts the Home Folder path doesn't work for our use case.
So far I've found two scripts on my travels that seem popular:
I've had more luck with the first one, which maps correctly if I put a sample user's full path into the Script Parameter #4 but not if I try to use a variable in there. As I understand I should be able to use $3 to get the logged-in username for a Policy that runs at User Login? However that doesn't seem to work.
Have also tried hardcoding that path into the script e.g.
However the script seems to take that a bit too literally and maps to the path including $3, rather than replacing it with the currently logged in user's name,
Has anyone found the correct syntax mix to get dynamic paths working with a User Login Policy or are we trying to do something that doesn't work?
I have not done any of this, but you may be able to get the currently logged in user with something like...
loggedInUser=$(/usr/bin/python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None]); username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + " ");')
I've often had spotty results using $3 in scripts, even with login policies, to get the current user. I don't know why, but using something like what @robmorton mentions above should get you more consistent results. Since you're using a script for this, you have the freedom to use whatever means you need to get the current logged in username in a variable and populate the share path with it. You don't have to use the pre-defined variables that Jamf uses for it.
One other thing that you would want to test is that there may be a timing issue thing going on. If the script runs right away, the $3 may not be known. If it waits a couple seconds it might. Using a means to determine who is logged in allows you to control the process a bit more. Prior to checking for the logged in user sleep X seconds or something like that.