The macosxhints Forums

The macosxhints Forums (http://hintsforums.macworld.com/index.php)
-   UNIX - Newcomers (http://hintsforums.macworld.com/forumdisplay.php?f=15)
-   -   Automount network home folder using AD path (http://hintsforums.macworld.com/showthread.php?t=106139)

lennysweet 10-08-2009 04:11 PM

Automount network home folder using AD path
 
Hello,

I have been managing a mixed bag of Macs and PC's in a large school district for a of couple years now. There is something that has me feeling completely stupid because it seems like something so simple that is very hard to accomplish on my macs.

I have a working Active Directory/Open Directory environment using AD for login and Windows smb: shares for network home folders. When users login they have a shortcut to their home folder, as specified in Active Directory, appear on the dock.

The problem with this, which has been discussed at great length in many forums, is that a dock shortcut is useless when trying to save a file within an application like textedit, Microsoft Word, ect. What user's need is either a way to automount a desktop shortcut to the Active Directory home folder following the same code and method the dock shortcut is created so that it can be pulled up in a finder window when the user goes to save.

The only viable workaround has been to manually drag a shortcut to the user's home folder over to the sidebar under "Places" so they have access to it within programs. This has been working OK for computers that aren't shared, but for labs and other public places it's not a good solution since this has to be done for each user profile that logs in.

What I'm looking for is a way to have a login script or startup item set that will check the logged in user's account and create a shortcut on the desktop to that user's home folder using the path specified in Active Directory.

Has anyone out there ever seen this accomplished? Any help would be greatly appreciated.

Thanks,
John

tlarkin 10-08-2009 04:48 PM

Well there are a couple ways we could go about doing this....let me just toss the ideas at you.

1) Create OD users/groups based on your AD users/groups and use Work Group Manager to map their home directories to the SMB shares. Then say, set policy to create mobile accounts. That way their synchronize their home directory to the machine but still store their home folders on the SMB share on the Windows server.

2) Same thing as 1 but use network homes instead of mobile homes

3) Create a log in hook via launchd that will pull out the currently logged in user and map their drive. I think that if you wanted to have this happen with out authentication kerberos would have to be running so that user could be issued a kerberos ticket.

4) Apple script it, make it an application, let the user interact with it so they can input their password. This is probably not the ideal way to do it, but it is possible.

lennysweet 10-12-2009 07:41 AM

I have been researching how to accomplish your third suggestion but cannot find anyone out there with an example of a login hook that would pull the user's home folder path from AD and mount it. Kerberos is running and my user's are granted a ticket when they login so it would just be a matter of finding the code.

I am fairly new to OSX system's management and have very little experience with the Unix command line so any help with the syntax would be greatly appreciated.

I found this arcticle... http://www.macenterprise.org/article...hadhomefolders
However, the link to the code is broken and I've never been able to find it.

tlarkin 10-12-2009 08:41 AM

Quote:

Originally Posted by lennysweet (Post 556862)
I have been researching how to accomplish your third suggestion but cannot find anyone out there with an example of a login hook that would pull the user's home folder path from AD and mount it. Kerberos is running and my user's are granted a ticket when they login so it would just be a matter of finding the code.

I am fairly new to OSX system's management and have very little experience with the Unix command line so any help with the syntax would be greatly appreciated.

I found this arcticle... http://www.macenterprise.org/article...hadhomefolders
However, the link to the code is broken and I've never been able to find it.

I know a method from shell....

this is an example:

Code:

#!/bin/bash

#pause for kerberos ticket

#/bin/sleep 20

#get current logged in user

cur_user=`/bin/ls -l /dev/console | awk '/ / { print $3 }'`

#input full path of home folder

home_folder="/Volumes/path/to/folder"

#now make sure it is mounted

if [[ $home_folder -e ]]

  then /bin/echo "home folder is mounted"

  else /sbin/mount_smbfs //domain; $cur_user@]server/share

fi

/bin/echo "done"

exit 0

Tried to keep it simple, you can edit what you need and test it out, and if kerberos is running full speed the ticket the user gets when they log in should allow them to map the home with out authentication.

Now, the script may need a delay, so I did put a delay in there, but it is commented out. Just remove the # to invoke the sleep command so they log in and get the ticket first. I set it to a 20 second delay just as a precaution. Not sure if you need the delay or not, but you can tweak it as needed.

lennysweet 10-12-2009 08:53 AM

Thanks for the fast reply, I'll play with this a little and see if I can get it working.

tlarkin 10-12-2009 08:57 AM

I don't have AD at work but we run ED from SuSe Linux on the PCs. I may have to integrate them one day myself so I try to keep up on things as I can. Let me know if it works out for you.

lennysweet 10-12-2009 09:20 AM

I tried plugging the code into script editor but I'm getting syntax errors on the following line...

if [[ $home_folder -e ]]

It didn't seem to like the $ so I added quotes like this...
if [[ "$home_folder" -e ]]

Now it's saying "expeted else but found then" error on this line...
then /bin/echo "home folder is mounted"

I don't know how to get past this point (or even if my quotes fixed anything) Is there a better script editor I should try? I am using Apple's script editor which will not let me save this code as script if there is anything that it considers a syntax error.

tlarkin 10-12-2009 09:26 AM

did you copy and paste it directly....

Copy and paste it into a plain text file, not rich text and save it as myscript.sh then try running it and editing it from there.

lennysweet 10-12-2009 09:28 AM

I did copy/paste it directly into script editor and immediately tried to save it (which is my way of checking syntax right out of the gate)

tlarkin 10-12-2009 09:34 AM

Quote:

Originally Posted by lennysweet (Post 556883)
I did copy/paste it directly into script editor and immediately tried to save it (which is my way of checking syntax right out of the gate)

What script editor? You should just copy/paste it into a text editor.

lennysweet 10-12-2009 09:54 AM

I'm trying it now, sorry for the confusion

lennysweet 10-12-2009 10:02 AM

OK, there's still a problem on line 17

if [[ $home_folder -e ]]

I tried executing the script through ARD on a test machine and it's reporting errors on this line, the output reads...

/bin/bash: line 17: conditional binary operator expected
/bin/bash: line 17: syntax error near '-e'
/bin/bash: line 17: 'if [[ $home_folder -e ]]'

any ideas?

tlarkin 10-12-2009 10:04 AM

Quote:

Originally Posted by lennysweet (Post 556891)
OK, there's still a problem on line 17

if [[ $home_folder -e ]]

I tried executing the script through ARD on a test machine and it's reporting errors on this line, the output reads...

/bin/bash: line 17: conditional binary operator expected
/bin/bash: line 17: syntax error near '-e'
/bin/bash: line 17: 'if [[ $home_folder -e ]]'

any ideas?

Yeah, I am retarded. Not enough coffee yet this morning, swap the -e and $home_folder

if [[ -e $home_folder ]]

lennysweet 10-12-2009 10:09 AM

thanks, we're getting close now. It spit back a "no such file or directory" message but the script executed and pulled the username just fine. I'm going to try to play around a little more with the server path to see if I can get it. Thanks again for your help this morning. I've gotten farther in the past hour than I have all year!

tlarkin 10-12-2009 10:14 AM

No problem at all. Please copy/paste the final solution to the forum so other readers can benefit from the solution down the road.

lennysweet 10-12-2009 10:49 AM

I'm not having any luck, here is what I'm trying to use (my real FQDN was replaced with mydomain.com)

#!/bin/bash

#pause for kerberos ticket

#/bin/sleep 15

#get current logged in user

cur_user=`/bin/ls -l /dev/console | awk '/ / { print $3 }'`

#input full path of home folder

home_folder="/Volumes/classof2011/"

#now make sure it is mounted

if [[ -e $home_folder ]]

then /bin/echo "home folder is mounted"

else /sbin/mount_smbfs //mydomain.com; $cur_user@]HS3/classof2011

fi

/bin/echo "done"

exit

The output reads as follows...

usage: mount_smbfs [-Nh] [-d mode] [-f mode]
//[domain;][user[:password]@]server[/share] path
/bin/bash: line 21: balboar@]HS3/classof2011: No such file or directory
done

I've played around with different things but nothing is working. I know the user is Kerberized because I was able to do a Go>connect to server, type in smb://hs3/students/classof2011/balboar and the "balboar" folder mounted on the desktop as an smb volume without having to authenticate. What am I missing?

tlarkin 10-12-2009 10:52 AM

you may be able to drop the user part of the script from the mount_smbfs command?

From the command line if you log in as that user and get a kerberos ticket and use mount_smbfs to mount the full path does it mount?

We may have to try just the mount command if that doesn't work. Is their home folder named their short name? There is also a space in that script from when I copied/pasted the syntax from the man page. There should probably be no space after that ; in the script. Try deleting that. I don't have a SMB share to verify.

lennysweet 10-12-2009 11:15 AM

I have not been able to run the mount_smbfs command successfully after trying all sorts of different syntax. I'm either getting a"file does not exist" error or "command not found" error.

According to Workgroup Manager, one of my test user's short names is balboar which is the same name as the home folder on the server. However, I don't think the command is attempting to mount smb://hs3/students/classof2011/balboar directly like the "connect to server" function. Is there any way to modify the script to pull the path from Active directory and attempt to mount it that way? Maybe using an ldap command.

Somehow OSX's AD plugin is able to do this for home syncing and placing the dock shortcut.

tlarkin 10-12-2009 11:22 AM

Try just the mount command with the FQDN instead of mount_smbfs perhaps?

lennysweet 10-12-2009 11:41 AM

No luck, it's just spitting back errors no matter what I try to do. I just wish there was option to do this is Workgroup Manager. I'm thinking that even I get this script to work it was have to be customized for each of my file servers. What I'm ultimately trying to do is mount the user's home folder the same way the dock shortcut is created so that no matter what server their home lives as long as the the computer is bound to AD and OD it will mount the volume on the desktop. I would even settle for an alias to the home folder be automatically created on the user's desktop at login. Both of these options always sounded so simple to me but may be out of reach.

Thank you very much for your help with this. Hopefully someone else having the same problem will see this post and offer their solution.

tlarkin 10-12-2009 11:49 AM

Quote:

Originally Posted by lennysweet (Post 556912)
No luck, it's just spitting back errors no matter what I try to do. I just wish there was option to do this is Workgroup Manager. I'm thinking that even I get this script to work it was have to be customized for each of my file servers. What I'm ultimately trying to do is mount the user's home folder the same way the dock shortcut is created so that no matter what server their home lives as long as the the computer is bound to AD and OD it will mount the volume on the desktop. I would even settle for an alias to the home folder be automatically created on the user's desktop at login. Both of these options always sounded so simple to me but may be out of reach.

Thank you very much for your help with this. Hopefully someone else having the same problem will see this post and offer their solution.


You most likely can do it with WGM, I had no idea you were also running OD along with AD. You can set automounts via computer policy in WGM.

Go into WGM, click on the computer list, use your guest computer or your computer group and select preferences, then select Login. On the last tab of the Login pref pane there is an option called "Items" and there is an automount home folder using user name and password option.

I didn't think you were using OD with AD, otherwise I would have suggested this via MCX in the beginning.

lennysweet 10-12-2009 12:40 PM

By George I think I've got it!

I ran the following script though ARD to a computer already logged in and kerberized

#!/bin/bash

#pause for kerberos ticket

#/bin/sleep 15

#get current logged in user

cur_user=`/bin/ls -l /dev/console | awk '/ / { print $3 }'`

#input full path of home folder

home_folder="/Volumes/path/to/folder"

#now make sure it is mounted

if [[ -e $home_folder ]]

then /bin/echo "home folder is mounted"

else /sbin/mount_smbfs //172.20.0.6/students/classof2011/$cur_user /Users/$cur_user/Desktop

fi

/bin/echo "done"

exit 0

It seems like using the IP instead of the DNS name is what worked. I know DNS is configured correctly but for some reason the mount_smbfs command didn't like it.

When I ran this, it mounted the user's home folder on that user's desktop and it appeared automatically under places in finder. Now all I have to do is figure out how to implement this as a login scripts through Workgroup Manager. Thanks again for all your help, I hope this helps someone else out there trying to do the same thing.

lennysweet 10-12-2009 01:30 PM

I am having one small problem I can't seem to figure out. This script only works if the root sharepoint is not already mounted. In other words, in my example above the script worked because the volume smb://172.20.0.6/students does not automount when the user logs in, only smb://172.20.0.6/classof2016. So, the script allowed a new volume to be mounted using the full path smb://172.20.0.6/students/classof2016/$cur_user

The problem is, most of my other file servers are setup with everyone's home folder at the root. So if a user's home folder is in smb://172.20.0.6/students the script gives the message "file exists" because the "students" sharepoint is already mounted on that user's desktop at login in order to give them the shortcut on the dock.

I hope this makes sense, obviously moving home folders into subfolders is not going to be an option. Is there any way to force the script to execute even if it thinks the file already exists?

tlarkin 10-12-2009 02:12 PM

Try editing my line that has the home_folder variable to the actual full path, so in your case...

home_folder="/Volumes/students/classof2011/$cur_user /Users/$cur_user/Desktop"

..I think that is how OS X will mount the home directory. Since the script I gave you checks to see if that full path exists first, and if it does then it exits because it is already mounted. If it doesn't exist it mounts it.

lennysweet 10-12-2009 02:13 PM

sorry I wasn't more clear about our environment earlier. I am very familiar with the login items option in Workgroup Manager but it does not actually mount the user's home folder, only the sharepoint or root share appears on the desktop. The dock shortcut is correct and is set to the user's home folder but the desktop only mounts the share, not the folder. In order for a user's home folder to automount on the desktop, smb shares would have to be created for each user rather than just on the root which is not very secure. This would also put a much heavier load on the file server having to deal with several thousand smb shares instead of just one.

I know it's possible to mount the individual folder as a network volume on the desktop simply by typing in the fully smb://server/share/homefolder path using "connect to server" but for some reason OSX only mounts the root smb share and stops. That has been my problem from day 1 which is why I've been trying to find a workaround using scripting.

Your idea is working but only for home folders nested within a subfolder like I said in my last post.

lennysweet 10-12-2009 02:17 PM

I didn't think about modifying that line, I'm going to test that now. I'll post back in a few minutes

lennysweet 10-12-2009 02:20 PM

no luck, I still get a "File Exists" message since the root share is already automounted at login. If I disconnect the root share and run the script again it works fine. Argh!

tlarkin 10-12-2009 02:23 PM

Quote:

Originally Posted by lennysweet (Post 556951)
no luck, I still get a "File Exists" message since the root share is already automounted at login. If I disconnect the root share and run the script again it works fine. Argh!

We can modify the [[ -e $home_folder part ]]

I just scripted it as if there was nothing mounting it but the script itself. So that volume auto-mounts at log in?

You can have WGM run the script as a log in hook on a computer group and totally ditch the auto mount, or we can modify the script so it just does it regardless. I used an if/then statement to lessen the load on the server from users hitting it if the mount already exists.

If it already exists we may be able to use an apple script to tell the finder to mount the folder path on the desktop.

lennysweet 10-12-2009 02:28 PM

I would prefer not to ditch the automount because of the shared folders users access through the root share and I believe it's required if I still want to keep the dock shortcut.

If there is any way to modify the script to run regardless, I would like to try that first.

An applescript would be great too, I could do a bunch of things with that using Automator.

tlarkin 10-12-2009 02:40 PM

Well try this apple script

Code:


tell application "Finder"
       
        mount volume "smb://user@domain.mycompany.com/sharepoint"
       

end tell

I don't know the vocabulary off the top of my head for it to grab the current user.

lennysweet 10-12-2009 02:55 PM

The applescript is having the same issue, if the sharepoint is already mounted on the desktop the script runs but does nothing since it thinks the volume is already there. If I disconnect the root sharepoint and run it again, it works.

tlarkin 10-12-2009 03:08 PM

Quote:

Originally Posted by lennysweet (Post 556963)
The applescript is having the same issue, if the sharepoint is already mounted on the desktop the script runs but does nothing since it thinks the volume is already there. If I disconnect the root sharepoint and run it again, it works.

So, if it is already mounted and the have a kerberos ticket all you need to do is to have it show up on the desktop? I guess we could just script out an alias or make an alias that way.

It really won't map the whole path of the home folder? I have not tried but the check box for home folders seems to imply that it will on different servers.

Instead of having it auto mount you could have it just run the script.

I guess you can also try the script like this:

Code:

#!/bin/bash

#get current logged in user

cur_user=`/bin/ls -l /dev/console | awk '/ / { print $3 }'`

/sbin/mount_smbfs //172.20.0.6/students/classof2011/$cur_user /Users/$cur_user/Desktop

exit 0


lennysweet 10-12-2009 03:19 PM

this script acts the same as the first one only it doesn't bother checking to see if the voluem exists. The end result is the same unfortunately, with the root sharepoint "classof2011" already on the desktop, the script reports that the file exists. If I disconnect the root share and retry it works.

I understand that I am not dealing with drives and mapping but instead a volume but I know it's possible to bypass this rule since typing in the full path using "connect to server" mounts the folder as a separate volume right next to the root folder. I just can't seem to get it to work using a script.

lennysweet 10-12-2009 03:21 PM

I found this in another forum, this is exactly what my problem is and the way it was explained makes sense but of course, no one chimed in with a workaround

http://forums.macrumors.com/archive/.../t-472070.html

tlarkin 10-12-2009 03:51 PM

Well, how comfortable are you with the command line? You can try creating a directory and then creating a symbolic link to the automount that is already mounted.

It is not hard, but it may be a bit more work and may have a higher failure rate, but I think it may be worth a shot.

So uh, something along these lines.

Code:

#!/bin/bash

#create a sym link to an already mounted nested folder

#grabbing current user

cur_user=`/bin/ls -l /dev/console | awk '/ / { print $3 }'`

#now make sure volume is mounted

home_folder="/Volumes/students/classof2011/$cur_user"

if [[ -e $home_folder ]]

then

#change winmount to whatever you want

/bin/mkdir /Users/$cur_user/Desktop/win_mount

/usr/bin/chown -R $cur_user:staff /Users/$cur_user/Desktop/win_mount

else

/bin/echo "folder not mounted exiting"

exit 1

fi

#create the symbolic link

/bin/ln -s /Users/$cur_user/Desktop/win_mount /Volumes/students/classof2011/$cur_user


exit 0

That is kind of quick and dirty but you may want to play with it. It will link whatever folder you create on their desktop to the actual share. however, symbolic links will break if anything on any system changes a lot of times so as long as you test test test test test test test before you deploy they are OK to use.

I edited this to what I think it should be with out knowing anything about your environment so you may need to tweak my variables.

lennysweet 10-12-2009 03:54 PM

creating a sym link sounds promising, I'll dive into testing this tomorrow, it's time to go home now. Thanks again for all your help today. I'll post back soon and let you know how it goes.

tlarkin 10-12-2009 04:09 PM

This would be a one time run script, as you wouldn't run it more than once. Once that folder and link are created your automount would take care of the rest.

lennysweet 10-13-2009 07:49 AM

No luck, even the symlink won't work because a "file exists" error. I'm not sure this would be a long-term solution anyway since it's a once and done sort of thing.

If there is anyway to force a mount using the same method as "connect to server" I think it would work but the command line is a little too picky

tlarkin 10-13-2009 09:27 AM

Try it from the command line.

manually make the folder, and then use this

/bin/ln -s /Users/$cur_user/Desktop/win_mount /Volumes/students/classof2011/$cur_user

but modify it to reflect the actual paths and folders with out the variables.

lennysweet 10-13-2009 03:10 PM

no luck doing this manually either. I created a folder called "test" on the desktop then opened terminal and typed in

/bin/ln -s /Users/balboar/Desktop/test /Volumes/students/classof2011/balboar

The command didn't produce any errors but nothing happened. The folder remained an empty folder. I disconnected the classof2011 volume from the desktop and the command gave me a "file does not exist" message.

tlarkin 10-13-2009 03:23 PM

Well, I am not sure why it is not working, that sure is odd. I wish I knew more about apple script as I am sure there is a way to alias that folder on the desktop.

I can look into it and get back. I do not use automount in my environment because I don't want 8,000 clients automounting shares. So, instead I use scripts which are triggered by actions. Seems to work OK for me.

lennysweet 01-19-2010 02:58 PM

New Life to an old issue
 
I wanted to bring some new life to this old topic in case someone out there has been able to accomplish this. To save you the trouble of reading the whole thread, I'm basically running Active Directory and Open Directory together and would like to find a way to have a shortcut to a user's home folder appear automatically at login the same way the shortcut on the dock is created. The reason for this is the dock shortcut is only available from the desktop and not from within applications. So when a user tries to save, they still have to drill all the way down through the network to their home folder in order to do so. The workaround up until now has been to have a tech login as the user and create a shortcut to their home folder for them under "places" in finder. I would like to automate this process to save our tech's time and to allow users to go computer to computer without having to be setup to save this way.

Bottom line, I would like to accomplish one of the following...

1. Have a symlink or alias created on the desktop automatically to the user's home folder using the same code or script that runs to create the dock shortcut (I have no idea where the code for this is buries in OSX, I can't find it)

2. Have the user's folder show up automatically under "places" in finder when they login.

If anyone thinks they may be able to help me, please reply. This seems like such a simple thing to do but it's turned out to be quite impossible.

palan 02-18-2010 11:13 AM

Hi Lenny,

Im trying to do the exact same thing as yourself, not getting anywhere.
Been looking at web forums for months and came across this one during the week.
I had a look at the script you were working on with tlarkin.
One thing i noticed when running this. if you go back to the basics of just getting the current user, im not sure this returns any value when being ran against an AD account.

For example, if i run the whoami command or just use $USER in a simple bash script when logged on as a local user and echo it back out to the screen, it returns the username that is logged on.
i just had it do the following

echo 'user logged in is:' $USER

which returned
user logged in is: admin

Set this up as a loginhook and then logged in as a user that is in AD (the mac is binded to AD and OD)
when i logged in and checked the console in utilites, it returned
user logged in is:
doesnt return anything
same with the whoami command.

Ive tried this on a mac running 10.5 and also 10.6, both binded to OD and AD.

Were trying to set it up so that all users home folders are stored on a windows 2003 R2 box, and have it working in a way that when the user logs on, their home folder appears in the dock.
Only problem with this is that if they are using MS word or Adobe Photoshop, and click file -> save as, they have to browse the network and be able to identify where their home folder is on a server.
most of our users arent savy enough to know this.
Reason we have our home folders on a 2003 server box is that the users will also be logging into windows XP machines.

We dont want to go down the road of using mobile accounts, as I work in a college and most users tend to forget to log out when finished, meaning their files would not be synced up to their home folders

so, to go back to basics, does anyone know a way of getting the currently logged on username when it is an Active Directory account?

lennysweet 02-19-2010 07:39 AM

Frustrating isn't it? I wish there was a way to grab the code that OSX uses when it creates the dock shortcut. It does exactly what I'm trying to do except I want the shortcut on the desktop or under "Places" in finder. Hopefully somebody will reply to this someday that figured it out.

tlarkin 02-19-2010 09:58 AM

Have you tried creating a mount point in WGM and then using it to map the home directories to the mac clients?

lennysweet 02-19-2010 10:00 AM

The mount point created in WGM only maps to the root share, what would I need to do to automatically create the home folder shortcut from that?

Hal Itosis 02-19-2010 10:19 AM

Quote:

Originally Posted by palan (Post 573012)
so, to go back to basics, does anyone know a way of getting the currently logged on username when it is an Active Directory account?

No idea about AD but, I wrote a script that checks identity a few different ways. Perhaps one of them will turn out to be usable.

$ cat whu
Code:


#!/bin/bash -
# script to compare various variables identifying the user
IFS=$' \t\n'
declare -x PATH=/bin:/usr/bin
UZER=`defaults read /Library/Preferences/com.apple.loginwindow lastUserName`
printf '\n %s %15s%15s\n' IDENTITY EFFECTIVE REAL
printf ' `id -un` %15s%15s <-- user \n' "$(id -u -n)" "$(id -r -u -n)"
printf ' `id -gn` %15s%15s <-- group\n' "$(id -g -n)" "$(id -r -g -n)"
echo ' _________________________________________________'
echo
echo USER/UID:
echo ' `whoami`              =' `whoami`
echo ' $LOGNAME              =' $LOGNAME
echo ' $USER                  =' $USER
echo ' $UID                  =' $UID
echo
echo ' $SUDO_UID              =' $SUDO_UID
echo ' ${SUDO_UID:-$UID}      =' ${SUDO_UID:-$UID}
printf ' $(basename ~)          = %s\n' "$(basename ~)"
echo ' ${HOME##/*/}          =' ${HOME##/*/}
printf "\n \$(dscl . -read ~ name|\n  awk '{ print \$2 }' ) = "
dscl . -read ~ name |awk '{ print $2 }'
printf "\n \$(ls -lb /dev/console|\n  awk '{ print \$3 }' ) = "
ls -lb /dev/console |awk '{ print $3 }'
echo ' _________________________________________________'
printf '\ndefaults read /Library/Preferences/\
com.apple.loginwindow lastUserName = %s\n' "$UZER"
echo
exit 0


lennysweet 02-19-2010 10:26 AM

This script did return a lot of useful info about the logged in user, including group membership, username even the User's ID#. I just don't know how to make a script that pulls this info and maps a home folder shortcut to the desktop.

Is there a command that pulls the AD user's home folder path? (there must be since the OD plug in can pull it) and if so, how can that command be used to create a desktop shortcut to that folder?

tlarkin 02-19-2010 10:36 AM

1 Attachment(s)
Quote:

Originally Posted by lennysweet (Post 573110)
The mount point created in WGM only maps to the root share, what would I need to do to automatically create the home folder shortcut from that?

Well I have nested home folders on all my servers and I mount and the home folder path, the full path is clarified. You will need to probably make sure the mounts work in Server Admin first, then write in the full path.

I create presets, off a test user then import my users with those presets in WGM and it maps the full path, not just the root folder where the home folders live. I have different paths for every grade/school and they are all nested with in one parent folder called homes.

attached a screen shot

tlarkin 02-19-2010 10:40 AM

Quote:

Originally Posted by lennysweet (Post 573113)
This script did return a lot of useful info about the logged in user, including group membership, username even the User's ID#. I just don't know how to make a script that pulls this info and maps a home folder shortcut to the desktop.

Is there a command that pulls the AD user's home folder path? (there must be since the OD plug in can pull it) and if so, how can that command be used to create a desktop shortcut to that folder?

In your set up, do you have users and groups in OD that mimic that of AD, and then you bind your client to AD just for authentication correct?

lennysweet 02-19-2010 10:58 AM

No, we do not import users into OD so I cannot configure the users like you do. We use AD for authentication and Preferences but we only use Open Directory groups for this and then make AD user groups members of the OD groups. The AD plug in allows for the user's home folder to appear on the dock, I'm trying to harness that exact same process to put a shortcut on the desktop instead.

tlarkin 02-19-2010 11:14 AM

Quote:

Originally Posted by lennysweet (Post 573119)
No, we do not import users into OD so I cannot configure the users like you do. We use AD for authentication and Preferences but we only use Open Directory groups for this and then make AD user groups members of the OD groups. The AD plug in allows for the user's home folder to appear on the dock, I'm trying to harness that exact same process to put a shortcut on the desktop instead.

Ah OK, I see now, I guess I was not grasping that before, sorry for any confusion I may have given. Well, is that even an option? If you were to import all users from LDAP from AD into OD you could completely manage and all sorts of stuff which I do in OD. I know that may not be an option for you so I won't venture any further, but maybe it will be something you can ponder and campaign for down the road.

Now, looking at your issues at hand. If the AD plug in puts the home folder on the dock, and it is mapped to the home folder in AD on the AD servers, have you tried just creating a folder which is an alias to the dock, or do you want the folder to actually be physically moved to the desktop?

I haven't used AD much in the past 3 years because this current job I have is pure OD, but my last job did have AD so I am rusty on it.

lennysweet 02-19-2010 11:17 AM

That would work but I have no idea how to create an alias to the dock, I didn't think that was possible.

tlarkin 02-19-2010 11:23 AM

OK, so when you log in to a machine and the home folder is mounted, where is it mounted at? Assuming somewhere in /Volumes?

Can you get that info?

lennysweet 02-19-2010 11:38 AM

The home folder shortcut on the dock is nester two, sometimes three levels deep but the root volume is mounted on the desktop. In other words, I have share in \\server\myshare\subfolder\myhome

The dock has a shortcut to myhome but the volume that is mounted is myshare.

I would like that shortcut directly to the home folder placed not only on the dock but on the desktop or under "places" in finder.

tlarkin 02-19-2010 11:43 AM

OK in post #39 of this thread I suggested making a symbolic link. So if you create a folder on the desktop and then link it to that full network path, does it work?

if you log in, and have one mounted what is the output of this command:

ls -al /Volumes

lennysweet 02-19-2010 11:59 AM

Unfortunately creating a symbolic link didn't work, I just get a "file does not exist" message. I do not think this would be a practical solution anyway since an emply folder would have to be created at login and them mapped as a symlink to the home folder through a script.

The output of the command you gave me shows the network volumes and the local hard drive as well as my permissions to each.

tlarkin 02-19-2010 01:05 PM

So it doesn't actually put anything on the machine, ie it doesn't mount anything. It just puts a dock item that is an alias to a network share?

palan 02-26-2010 06:27 AM

I logged in as an AD user, the home folder appears on the dock.
I typed in the command:

ls -al /Volumes

and it returned the following
total 56
drwxrwxrwt@ 5 root admin 170 26 Feb 10:36 .
drwxrwxr-t 35 root admin 1258 25 Feb 14:02 ..
-rw-rw-rw-@ 1 admin admin 6148 26 Feb 10:35 .DS_Store
lrwxr-xr-x 1 root admin 1 26 Feb 10:26 IMAC05 -> /
drwxrwxrwx+ 1 4294967195 MYDOMAIN\domain users 16384 25 Feb 15:04 Personal$

(ive substituted our real domain name with "MYDOMAIN in the above output)
The name of the machine in this example is IMAC05

the user that is logging on is called "mediauser" and their home folder is located on a windows 2003 server in a share called "Personal$"
\\myserver\Personal$\mediauser

From my understanding, the folder that contains all of the home folders (i.e. Personal$) is mounted as a volume, but the users home folder is not, so not sure if you can use the info here to create an alias to the users home folder and place it on the desktop

Any ideas?

tlarkin 02-26-2010 10:44 AM

Hmm,

I don't have AD, but it seems it does mount the folder here...

drwxrwxrwx+ 1 4294967195 MYDOMAIN\domain users 16384 25 Feb 15:04 Personal$


So the question is, can you alias that mount (or sym link) to a folder that shows up on the desktop. Have you tried searching through the forums over at www.afp548.com? There are lots of AD/OD articles over there.

palan 02-26-2010 11:22 AM

I donwloaded something called osxutils, which contains a handy command called mkalias which, if manually done, allows me to create an alias of the home folder into my profile.

Ill try and explain this as best I can.
if i login as the AD user called "mediauser", the machine is setup to create the profile locally, so it creates /Users/mediauser and stores their profile in there.
If i use this mkalias cmd, I can run it in a terminal...

mkalias /volumes/Personal$/mediauser Homefolder

this creates an alias in the profile called "Homefolder" which points at the users home folder stored up on the windows 2003 server, which will now allow the user to save into their home folder when using the likes of word or photoshop by clicking file -> save as and browsing to the alias called "HomeFolder"

Only problem now (Still) is that if i try to put this into a loginhook, i still cant get it working so that I can identify who is currently logged on and append it to the mkalias cmd...
i.e.

USER = ??
mkalias /volumes/Personal$/$USER Homefolder

Ive tried using $LOGNAME, $USER, whoami, but all return either root, nothing, and sometimes even .spotlight (or something like that).
you'd think this was the easy bit!

tlarkin 02-26-2010 11:28 AM

Dude, that is easy. Whatever user is logged in, always owns the console. So you can easily see which user it is, by doing this:

Code:

ls -l /dev/console | awk '{ print $3}'
my results:

bash-3.2# ls -l /dev/console | awk '{ print $3}'
tlarkin


So, just set a variable for that command and then call it to map that specific user. This is because all log in hooks are ran by root, and not by a specific user. So root is always going to own the log in hook no matter what.

palan 02-26-2010 12:01 PM

this might sound like a stupid question, but how would i get this to run if i dont set it as a login hook?

as you mentioned, running a script as a login hook will always run under the root user, so is there a way to have a script run on startup that doesnt run under the root user?

our preference is to have this setup in the background so any user who logs on, a script will run and create the alias

tlarkin 02-26-2010 12:05 PM

Quote:

Originally Posted by palan (Post 573996)
this might sound like a stupid question, but how would i get this to run if i dont set it as a login hook?

as you mentioned, running a script as a login hook will always run under the root user, so is there a way to have a script run on startup that doesnt run under the root user?

our preference is to have this setup in the background so any user who logs on, a script will run and create the alias

Use launchd and put the script in ~/Library/LaunchAgents and it will run when that user logs in, but I think this also runs as root. My method is pretty simple though and has worked out for me rather well.

palan 02-26-2010 12:17 PM

I presume when you mention your method, is it just a case of running the command in the terminal window yourself?

Only problem with that is the environment Im looking after is a college, and even the mention of terminal will send them running!!

tlarkin 02-26-2010 01:16 PM

Quote:

Originally Posted by palan (Post 573998)
I presume when you mention your method, is it just a case of running the command in the terminal window yourself?

Only problem with that is the environment Im looking after is a college, and even the mention of terminal will send them running!!

Well here is what I would do.

1) create a script that can either output the currently logged in user and have it execute with the commands you used to create the home folder alias with.

2) Create a launchd item and place it in /Library/LaunchAgents. Launch Agents will run any time any user logs in. You may want to create a loop with an if/then so if a local account logs in the script exits.

3) Copy out your launch agent plist and your script to every machine locally, or have Open Directory run it via MCX

4) use launchctl to permanently load it and now you have a working log in hook that runs under the hood with no user interaction. It just simply works.

palan 03-01-2010 09:14 AM

cheers for that, ill give it a go later on and let you know how it goes.
We have a mac server that the clients are bind to (they are also bind to AD) so ill try run it via MCX

kaptagat 03-04-2010 04:22 AM

Can I ask a basic question please?

How would one go about setting a variable to the results of that awk command?

Thanks

tlarkin 03-04-2010 09:50 AM

Quote:

Originally Posted by kaptagat (Post 574592)
Can I ask a basic question please?

How would one go about setting a variable to the results of that awk command?

Thanks

OK, lets say you wanted to modify a plist file in that user's home folder, the one that is currently logged in. Since the currently logged in users, by design, owns the console we can take that knowledge and apply it to a variable like so:

example:
Code:

#!/bin/bash

# grab the currently logged in user

CurrentUser=`ls -l /dev/console | awk '{ print $3 }'`

# now apply the plist modification

defaults write /Users/$CurrentUser/Library/Preferences/com.apple.AppleShareClient "afp_cleartext_allow" -bool true

exit 0

Since all log in hooks run as the root user you either have to full path it out to the user specifically you want to modify, or use the sudo -u command with the current user specified to run it as, so sudo -u tlarkin for example would run it as if the user tlarkin were running it.

kaptagat 03-04-2010 09:52 AM

Thanks Tlarkin but I managed to get it working this way :-

#!/bin/sh

me=$(ls -l /dev/console | awk '{print $3}')
mkalias /volumes/Staffusers/$me /Users/$me/Desktop/H_Drive

--------------------------------

This puts an alias of the user's folder on the desktop.

tlarkin 03-04-2010 09:58 AM

Quote:

Originally Posted by kaptagat (Post 574626)
Thanks Tlarkin but I managed to get it working this way :-

#!/bin/sh

me=$(ls -l /dev/console | awk '{print $3}')
mkalias /volumes/Staffusers/$me /Users/$me/Desktop/H_Drive

--------------------------------

This puts an alias of the user's folder on the desktop.

Awesome, glad it worked out for you.

kaptagat 03-05-2010 10:28 AM

The script works well during testing but fails in practice when logging in. I suspect it is because there are upwards of 2300 folders in the volume share and it can't parse the folder list in time. The system log simply says :-
volumes/staffvol/abc3 : no such file or directory.

Hal Itosis 03-05-2010 03:10 PM

Quote:

Originally Posted by kaptagat (Post 574782)
The script works well during testing but fails in practice when logging in. I suspect it is because there are upwards of 2300 folders in the volume share and it can't parse the folder list in time. The system log simply says :-
volumes/staffvol/abc3 : no such file or directory.

If that diagnosis is correct, then perhaps making a symlink instead of a Finder alias would be better.
[i.e., instead of mkalias, use /bin/ln -s ]

BTW, why does the error say "volumes/staffvol/" while your code has "/volumes/Staffusers/" ?

honestpuck 03-07-2010 07:08 PM

Hey guys,

Why don't you replace $(ls -l /dev/console | awk '{print $3}') with $(whoami) since you're after the currently logged in user. Or if you're doing this in a loginhook the last time I checked loginhooks get passed the current user in $1.

// Tony

tlarkin 03-07-2010 09:01 PM

Quote:

Originally Posted by honestpuck (Post 575040)
Hey guys,

Why don't you replace $(ls -l /dev/console | awk '{print $3}') with $(whoami) since you're after the currently logged in user. Or if you're doing this in a loginhook the last time I checked loginhooks get passed the current user in $1.

// Tony

Log in hooks run as root user so whoami would return root. I am not sure if $1 returns the current user as a log in hook or not.

honestpuck 03-07-2010 10:27 PM

I just checked and if you add the script as a loginhook to loginwindow.plist then you definitely get the logged in user as $1. It's working in 10.4, 10.5 and 10.6

// Tony

tlarkin 03-07-2010 10:31 PM

Quote:

Originally Posted by honestpuck (Post 575059)
I just checked and if you add the script as a loginhook to loginwindow.plist then you definitely get the logged in user as $1. It's working in 10.4, 10.5 and 10.6

// Tony

OK, that is what I was going to get at, if you have the loginwindow.plist control it. I knew you could do that, but a lot of times I have launchd control it, WGM control it, or Casper control it. So I always see who owns the console, and do it that way. There are always many different ways to accomplish the same task.

thanks for sharing

kaptagat 03-09-2010 09:29 AM

I use other scripts that use $1 with no problem but it doesn't seem to work with this one. Using the "awk" thing to get the user, I added a loginhook but it still doesn't work despite working OK if you drag the script into a terminal window and press return!
Even though I am logging in as abc1, the system log now says :-

09/03/2010 14:22:16 com.apple.loginwindow[1224] /volumes/Studhome/root: No such file or directory

tlarkin 03-09-2010 09:36 AM

Quote:

Originally Posted by kaptagat (Post 575245)
I use other scripts that use $1 with no problem but it doesn't seem to work with this one. Using the "awk" thing to get the user, I added a loginhook but it still doesn't work despite working OK if you drag the script into a terminal window and press return!
Even though I am logging in as abc1, the system log now says :-

09/03/2010 14:22:16 com.apple.loginwindow[1224] /volumes/Studhome/root: No such file or directory

You are using full paths? Since Studhome is not a standard home directory path. Make sure your scripts always use full paths, and are you still getting issues?

kaptagat 03-09-2010 10:25 AM

Sorry don't understand. It is a full path. Inside the "share" studhome there are thousands of student folders, one of which is abc1. The studhome volume is automatically mounted on the desktop when AD users logon. Their home folder, quite uselessly (can't "save as" to it), is added to the dock.

tlarkin 03-09-2010 10:41 AM

Quote:

Originally Posted by kaptagat (Post 575268)
Sorry don't understand. It is a full path. Inside the "share" studhome there are thousands of student folders, one of which is abc1. The studhome volume is automatically mounted on the desktop when AD users logon. Their home folder, quite uselessly (can't "save as" to it), is added to the dock.

Can you post your full script?

kaptagat 03-09-2010 11:55 AM

The script is in post 70. The "real" server share is studenth.

tlarkin 03-09-2010 12:43 PM

Quote:

Originally Posted by kaptagat (Post 574626)
Thanks Tlarkin but I managed to get it working this way :-

#!/bin/sh

me=$(ls -l /dev/console | awk '{print $3}')
mkalias /volumes/Staffusers/$me /Users/$me/Desktop/H_Drive

--------------------------------

This puts an alias of the user's folder on the desktop.

so taking this info here...let me see if I can shed some light

You have to have this run as a log in hook, by either using launchd to have it run at log in, or modify the loginhook.plist file to tell it to run the script and keep the script on the machines locally.

This is what you did?

kaptagat 03-10-2010 07:29 AM

I am running the script with login window manager which runs all my other scripts perfectly. To test things I changed the script to alias a specific folder of the person logging on, so no $ variables are passed, and it still fails, the system log saying /Volumes/studhomeh/abc1 : no such file or directory.

This also happens when passing the $ variable, it looks for the correct users's folder but can't find it. When run by itself, from the terminal, the script works perfectly, so I think the problem is down to the logging on procedure is so quick that the system doesn't have time to open the mounted volume and scan the 100s of folders for the correct one to alias.

tlarkin 03-10-2010 09:13 AM

Quote:

Originally Posted by kaptagat (Post 575390)
I am running the script with login window manager which runs all my other scripts perfectly. To test things I changed the script to alias a specific folder of the person logging on, so no $ variables are passed, and it still fails, the system log saying /Volumes/studhomeh/abc1 : no such file or directory.

This also happens when passing the $ variable, it looks for the correct users's folder but can't find it. When run by itself, from the terminal, the script works perfectly, so I think the problem is down to the logging on procedure is so quick that the system doesn't have time to open the mounted volume and scan the 100s of folders for the correct one to alias.

My guess is that the folder is not mounted yet and done so during log in. Try using the sleep command and make your script wait for 60 seconds and see if that makes any difference.

lennysweet 03-10-2010 09:35 AM

I've been playing around with this as well and it's giving me the same result "not found"

I do not think it's a timing issue. If I run the script manually after being logged in a while, it's still saying not found. I also has to change the command from mkalias to alias because the mkalias gave me a "command not found" message

I think we're getting close though, it looks like it might be the format of the path or something simple

tlarkin 03-10-2010 09:39 AM

How is the folder being mounted then? If it worked before it was because you had it mounted previously to running the script. You can have it mount the share in the script with the mount command, but if you did not do that before how was it being mounted?

lennysweet 03-10-2010 09:47 AM

The volume is being mounted at login and is called ECSERVER, here is the command I'm trying to run manually and in the script. ECSERVER is mounted on the destkop as I run the command.

alias /Volumes/ECSERVER/lenhartj /Users/lenhartj/Desktop/H_Drive

Output:

-bash: alias: /Volumes/ECSERVER/: not found
-bash: alias: /Users/lenhartj/Desktop/H_Drive: not found

If I run the command with mkalias the output reads "mkalias: Command not found"

is my syntax incorrect?

lennysweet 03-10-2010 09:51 AM

just a follow up, if I run the command ls /Volumes/ECSERVER/lenhartj it works fine and lists the contents of my folder

tlarkin 03-10-2010 09:58 AM

can you run this command and post the output?

ls -al /Volumes

Do it though after the share is mounted so we can see the mount point.

lennysweet 03-10-2010 10:05 AM

Sure thing, here is the output, looks like ECSERVER is in the list

TECH-IMAC:~ admin$ ls -al /Volumes
total 8
drwxrwxrwt@ 4 root admin 136 Mar 10 09:49 .
drwxrwxr-t 36 root admin 1292 Jan 14 12:35 ..
drwx------@ 112 admin staff 3764 Mar 8 08:01 ECSERVER
lrwxr-xr-x 1 root admin 1 Mar 8 15:08 TECH-IMAC -> /
TECH-IMAC:~ admin$

tlarkin 03-10-2010 10:24 AM

Try using the mkdir command to make the directory first for h_drive, then either alias it or use a symbolic link (ln -s). I mean we need to do it step by step to find out the missing step or location of failure, that way we can script it. You said it worked once, but nothing has changed and now it doesn't?

lennysweet 03-10-2010 10:34 AM

this worked great! I used the following and it mapped a folder with an alias inside of it to my network home.

mkdir /Users/$me/Desktop/H_Drive
ln -s /Volumes/ECSERVER/$me /Users/$me/Desktop/H_Drive

The only problem is I can't get the script to run using WGM. I added my imac in a test user group, then added this as a login script in Preferences>Login>Scripts

I logged in as me and nothing happened, is there some MCX refresh I need to perform?

tlarkin 03-10-2010 10:44 AM

In WGM, only computer groups can run log in hooks, not user groups. So you would have to create computer groups to do so.

Another way is to modify the loginhook.plist file and have it run the script, another way would be to have launchd run it from /Library/LaunchAgents, which will run anytime any user logs in.

lennysweet 03-10-2010 11:15 AM

how can I run it from /Library/LaunchAgents

I dropped the script in that folder but nothing happens, could you tell me what I'll need to do to get launchd to run it at login?

kaptagat 03-10-2010 11:20 AM

Lennysweet:

Your mkalias command not found is caused because the path to the command is missing. I had to put the full path as below when running the command from a script:-

/usr/local/bin/mkalias /volumes.....

I use Mike Bombich's LoginWindow Manager to launch scripts at login and logout. It is quite old now and complains about fonts when you start it up but it still works right up to 10.6.

tlarkin :

Adding a sleep period didn't make any difference.

lennysweet 03-10-2010 11:22 AM

the ln -s is working fine, my problem now is I can't seem to get it to run at login. Could you give me details instructions for getting this script to run for any user who logs in?

tlarkin 03-10-2010 11:37 AM

create a luanchd agent like so:

Code:

<?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.0">
<dict>
        <key>Label</key>
        <string>com.mycompany.loginhook</string>
        <key>ProgramArguments</key>
        <array>
                <string>/Library/Scripts/myloginscript.sh</string>
        </array>
</dict>
</plist>

Then place this agent in /Library/LaunchAgents and make sure to give it the plist extension. Then place your log in script in /Library/Scripts, or where ever you want adjusting the path.

Then use launchctl to load your launchd item permanently.

(run as root)
Code:

sudo launchctl -w load /Library/LaunchAgents/com.mycompany.loginhook.plist



Now anytime, any user logs in, it will run. You can also modify the local file /Library/Preferences/com.apple.loginwindow.plist to have it run the script as well.

If you import computer names into WGM you can manage it by computer groups, or create a guest computer and assign it that way. However, a guest computer will get assigned to all macs in your deployment, as it is the default computer for all computer groups.

---EDIT----

I went back and outlined what you would have to fill in for your settings. After it is loaded you may have to reboot to get the agent to run. To ensure it is running you can use launchctl list command to see if your agent is listed.

I have used this method in the past at my work and it has worked for me for automating scripts.

lennysweet 03-10-2010 11:58 AM

Wow, that's quite a process. I tried it and of course, it didn't work for me. When I ran the launchctl command with -w argument it said it could not be found. I removed it and got a "dubious ownership" error.

At this point I pasted the text into a file and named it com.rlasd.loginhook.plist and saved it into the Launchagents folder. I then save the the script named loginscript.sh into the scripts folder. I made sure all of the paths were correct so I'm not sure what I'm doing wrong.

Why does something as simple as a login script take so much command line knowhow geez!

kaptagat 03-10-2010 12:04 PM

Lennysweet:

Use loginwindow manager. It is very simple, you just drag your script into a run shell script at login box, tick the box and tick apply. Nothing could be simpler. It is also free.


All times are GMT -5. The time now is 10:17 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.