Mac OSX auto mount user's network drive

  • AnarchY SI
  • Web Master
  • Web Master
  • User avatar
  • Posts: 2521
  • Loc: /usr/src/MI

Post 3+ Months Ago

Hey, so we have a server running Windows Server 2003 setup with Active Directory login. The Macs can login to the server using the AD login, but with all of the users on the Windows XP computers, the My Documents folder gets mounted to the users H: drive on the network. How could this be done on the Macs? OS X v10.4.2
thanks :]
  • STeeLRaT
  • Graduate
  • Graduate
  • User avatar
  • Posts: 183
  • Loc: somewhere

Post 3+ Months Ago

http://www.Google.com

EDIT: I think this question is to hard. Googling will go faster than waiting for someone with a serious answer. This could take a couple week. If it's not a case of life or death you should just wait.
  • AnarchY SI
  • Web Master
  • Web Master
  • User avatar
  • Posts: 2521
  • Loc: /usr/src/MI

Post 3+ Months Ago

STeeLRaT wrote:
http://www.Google.com


did you HONESTLY just suggest google?
lmao

i'm not an idiot...
  • bleepnik
  • Professor
  • Professor
  • User avatar
  • Posts: 971
  • Loc: South Jersey, US

Post 3+ Months Ago

Did you ever figure this out? If not, can you rephrase what you're trying to do? I'm not sure I get it. Are you just trying to automatically mount a shared network volume when a (Mac) user logs in?

.g
  • teemilk
  • Born
  • Born
  • teemilk
  • Posts: 1

Post 3+ Months Ago

This is my apple script for Map Network Drive

Code: [ Select ]
set user_name to last word of (path to current user folder as text)
tell application "Finder"
    try
        mount volume "smb://" & user_name & "@server/" & user_name & ""
    end try
end tell
  1. set user_name to last word of (path to current user folder as text)
  2. tell application "Finder"
  3.     try
  4.         mount volume "smb://" & user_name & "@server/" & user_name & ""
  5.     end try
  6. end tell


1. You have to save as application.

2. Set it run everytime you logon computer by Go to system preferences -> accounts -> Login item

3. Copy com.apple.LaunchServices.plist and loginwindow.plist from /Library/Preference of your home folder account to /systemx/library/user template/English.lproj/Library/Preference.

4. Logon to AD Domain by Domain Account it with map drive with share as username of that account.
  • AnarchY SI
  • Web Master
  • Web Master
  • User avatar
  • Posts: 2521
  • Loc: /usr/src/MI

Post 3+ Months Ago

why thank you very much..

i will give that a try and repost with its results :]
  • dlegend
  • Born
  • Born
  • dlegend
  • Posts: 1

Post 3+ Months Ago

I'm sure the applescript option is great, but the simple way is to just drag the drive to the "log in items" of the "Users" pane in "System preferences".
  • AnarchY SI
  • Web Master
  • Web Master
  • User avatar
  • Posts: 2521
  • Loc: /usr/src/MI

Post 3+ Months Ago

dlegend wrote:
I'm sure the applescript option is great, but the simple way is to just drag the drive to the "log in items" of the "Users" pane in "System preferences".

yeaa.. THATS going to work for 5,000 users who all haven't logged in to the computer yet, but might. and it wouldn't even be remotely time consuming..



for some reason whenever i try the script stated here and i try to add it to login items to any user NOT root, the accounts window basically freezes. if i drag another window over and off of it it will show me the login items window, except it'll still be frozen and it wont have any buttons. arg :(
  • gutter
  • Newbie
  • Newbie
  • gutter
  • Posts: 5

Post 3+ Months Ago

Hey, don't know if this thread is still active but here's what you want to do, you want to create a login hook (if you don't know what it is Google it! There's ton of info out there about it including a gui called iHook) which is a shell script that run at login. The script itself will look something like this:

#!/bin/bash

mkdir /Volumes/<Share Name>
/sbin/mount -t smb smb://username:password@172.0.0.0/<Share Name> /Volumes/<Share Name>

This will mount the share with the given user name and password (for more information on the mount command type 'man mount' in the command line) at the mount point '/Volumes/<Share Name>' (which can actualy be anywhere you want but i like to keep OS conventions). Note, you probably want to set user name to 'guest' as there is no (thank god) variable floating around the operating system that contains the users password.
Also note, you have to give the full '/sbin/' address of mount, the only commands you can use in login scripts without giving their full path name are the ones in the '/bin' folder.
Okay, so save this file as something descriptive (like mapfolder.sh) and save it somewhere universal (I like /Library/Scripts/). When you're saving it, make sure it's in plain text format (so if you're using TextEdit to create it you'll have to go 'Format->Make Plain Text'), change the owner to 'root' and the make sure root has full access (in particular execute privileges):

(in command line type)

sudo chown root <Name Of File>
sudo chmod 700 <Name Of File>

Now we'll bind the script to the log in:

(in command line type)

sudo defaults write com.apple.loginwindow LoginHook /path/to/script/<Name Of Script>

And now, as long as you've done everything correctly, you should be golden. Restart and try logging in as a user (any user at this point, if you want to make the script more advanced and check if the user is local or not there are many good ways that can be found in other peoples scripts (in particular analyzing the Network Home Redirector script is fun and rewarding) but that is beyond the scope of what I'm trying to demonstrate here) and see if everything works. If not keep tweaking the script until its happy.

Finally I want to address some of the issues raised in the other posts:
The Applescript option is overkill in my experience (when OS X mounts a remote volume it does all kinds of background error checking and what not that i've found slow things down significantly) and the login items in the users Preferences are very hard to maintain with a large user base. If you do get something with applescript working you can always use osascript to port it to the command line and send it out via ssh, radmin, or any of a number of programs designed to help this kind of mass management. Finaly, the Login/Logout hooks are computer specific not user specific so you will have to deploy to every computer on the network and once again, without more functionality, it will run for every user who logs in.

Sorry about the state of my spelling, hope this helps everyone.
  • anilth
  • Newbie
  • Newbie
  • anilth
  • Posts: 6

Post 3+ Months Ago

Sounds your scripts is promising but one things is : I have a user home drive in samba, is there a way to modify this script so when user logs in they will get \\servername\username as a map drive and restart the machine as soon they logout. Perhaps it is possible by using login and logout hook. Can you point to this .
  • gutter
  • Newbie
  • Newbie
  • gutter
  • Posts: 5

Post 3+ Months Ago

Well, this should work just fine (unless I'm hideously mistaken samba is a SMB server), the variable $1 contains the user name of the current user in a shell script, beyond that its up to you to figure out how you want the process to work, where you want things to mount and if you want to share out each individual home directory, in which case you call is going to be something like:

/sbin/mount -t smb smb://username:password@172.0.0.0/$1 /Volumes/$1

(unix guys, let me know if this is syntacticly wrong, I'm not in a position to check it at the moment)

or if you want to share out the root folder containing the home directories and give users access to their individual folders some other way (not really recommended but there are situations in which it would work better). If you can clarify what exactly you're trying to do i could get a better idea of which direction to point you, besides of course o'reilly's OSX for Unix Geeks.
  • anilth
  • Newbie
  • Newbie
  • anilth
  • Posts: 6

Post 3+ Months Ago

hello gutter,

Thanks ! this is what I am trying to do- authenticate user AD - and when they logged in run the login script which will map their home drive in Desktop from like \\server\username. and when they logout run logout script to restart and unmount their drive (this is only because to bring up book picker menu). i manged to do logouthook, but following your instruction it doesn´t map the drive when user logs in. Note :

however if try to mapp manually by pressing apple key +k and do like smb://servername/username - supply username and password it does map. Which I don´t really want to do. It will be nice if mapping thing happens as soon as they login.

Thanks.

AT
  • AnarchY SI
  • Web Master
  • Web Master
  • User avatar
  • Posts: 2521
  • Loc: /usr/src/MI

Post 3+ Months Ago

you shouldn't need their AD username & password if the person is logged in to the computer with an AD account. do you have the computer joined to the domain?
  • anilth
  • Newbie
  • Newbie
  • anilth
  • Posts: 6

Post 3+ Months Ago

hello Anarch,

Yes, computer are joined the domain.

Rds,
A
  • AnarchY SI
  • Web Master
  • Web Master
  • User avatar
  • Posts: 2521
  • Loc: /usr/src/MI

Post 3+ Months Ago

hm..i dont recall whether or not the afp protocol needs to be enabled on the server, but either using smb or afp you as long as the user is logged on with an AD user account he/she shouldn't need to reauthenticate.. i.e. after logging on, if you go to connect to server and type: smb://your-server-address/folder OR afp://your-server-has-afp-enabled/folder it should bring up that folder without requiring authentication
  • gutter
  • Newbie
  • Newbie
  • gutter
  • Posts: 5

Post 3+ Months Ago

Here's the general way to solve the problem. Open up the terminal and use mount to mount a specified users home folder. Once you've figured out how to do that from the command line try making a script to do it automatically, substituting $1 for the user name. Finaly, once you have that working, drop your script into your login hook and enjoy.

There is one very important thing that you have to remember however, the mount command will not automatically grab the users password from anywhere. If you're trying to circumvent the normal network user login process (I'm a longtime proponent of OSX and I'll be the first to start bitching about how broken it is) you will have to get the user to type in their password somewhere and use that to mount their server share.

Good luck.
  • AnarchY SI
  • Web Master
  • Web Master
  • User avatar
  • Posts: 2521
  • Loc: /usr/src/MI

Post 3+ Months Ago

In my case, where the Mac was joined to AD and a network share was being mounted after login, AD credentials were not required to be provided after the user had logged in with their AD account.
  • anilth
  • Newbie
  • Newbie
  • anilth
  • Posts: 6

Post 3+ Months Ago

Hello Anarch,

Sorry for late reply but my mounting things are sorted according to your suggestion. Now here i am with another issue. I want to add the printer with script authentication against AD.

I am just thinking to create some script to do this. Ask user to download whenever they like and run it - supply the password and use the printer. is there any method to do this - or apple script would be fine too.

Thanks
  • AnarchY SI
  • Web Master
  • Web Master
  • User avatar
  • Posts: 2521
  • Loc: /usr/src/MI

Post 3+ Months Ago

that one i'm at a loss on.. someone more knowledgeable in the osx/applescript area will need to take the lead (O_o)
  • rlindenf
  • Born
  • Born
  • rlindenf
  • Posts: 1

Post 3+ Months Ago

Hello-

Based on what I've read, I'm trying to mount afp drives on user login. What I've done so far:

created a shell script:

Code: [ Select ]
#!/bin/sh

mkdir /Volumes/Users
/sbin/mount -t afp afp://$1@servername/Users /Volumes/Users
  1. #!/bin/sh
  2. mkdir /Volumes/Users
  3. /sbin/mount -t afp afp://$1@servername/Users /Volumes/Users


these commands, minus the /sbin, work from the command line. However, they do not work as a shell script when given:

Code: [ Select ]
sudo chown <filename>
sudo chmod 700 <filename>
  1. sudo chown <filename>
  2. sudo chmod 700 <filename>


and run via

Code: [ Select ]
sudo ./<filename>


nor do the run when passed to the loginwindow via:

Code: [ Select ]
sudo defaults write com.apple.loginwindow LoginHook /path/to/script


the error I get is:

Code: [ Select ]
mount_afp: the mount flags are 0000 the altflags are 0020
mount_afp: AFPMountURL returned error -5002, errno is -5002
  1. mount_afp: the mount flags are 0000 the altflags are 0020
  2. mount_afp: AFPMountURL returned error -5002, errno is -5002


does anyone know what I'm doing wrong?

thanks!

Ralph
  • JustDana
  • Born
  • Born
  • JustDana
  • Posts: 2

Post 3+ Months Ago

I know this is an old thread but "ADmitMAC" is a great program that integrates macs into a AD/windows environment. you can easily map SMB/AFS drives to any type of a server. Currently we are only mapping to server 2003 soon 2008 and maybe soon OSX server.

http://www.thursby.com/products/admitmac.html

You can setup the mapping for the drives for anyone who logs into said mac.

===============================================

AnarchY SI wrote:
In my case, where the Mac was joined to AD and a network share was being mounted after login, AD credentials were not required to be provided after the user had logged in with their AD account.
  • moonmonkey
  • Born
  • Born
  • moonmonkey
  • Posts: 1

Post 3+ Months Ago

I'm having a similar problem to anilth here.

I've created my login hook and it runs when a user login but it does not mount the network share. After checking the console I find I get this error.


com.apple.loginwindow[33] mount: exec /usr/sbin/mount_smb for /Volumes/resources$: No such file or directory

my script goes like this.

#!/bin/bash

mkdir /Volumes/resources$
/sbin/mount -t smb smb://username:password@bcsfs1/resources$ /Volumes/resources$

This should work fine, I've also found I get the No such file or directory error when I run the command minus the /sbin in Terminal. The most annoying thing about this is if I goto the Connect To Server window in Finder and put in those details then the network share mounts fine. Is there something wrong with the syntax? Or is there something wrong with mounting the volume. I don't know

Obivously I would much rather have the drive auto mount when the computers logs in rather than have users press Command + K and have them type in a path.

Any help would be great!

Cheers!
  • xylo
  • Born
  • Born
  • User avatar
  • Posts: 1

Post 3+ Months Ago

Have you tried to use AutomountMaker by JM Marino build by JMM Code Park :D
  • Othoman
  • Born
  • Born
  • Othoman
  • Posts: 1

Post 3+ Months Ago

This works perfectly on 10.6.4
  • ESGR
  • Born
  • Born
  • ESGR
  • Posts: 1

Post 3+ Months Ago

MAC OS 10.6.6
Code: [ Select ]
vi /mounts(dot)sh

Code: [ Select ]
R

Code: [ Select ]
#!/bin/bash

mkdir /Volumes/Volume_1
mkdir /Volumes/Volume_2
/sbin/mount -t smbfs //guest:@192.168.20.250/Volume_1 /Volumes/Volume_1
/sbin/mount -t smbfs //guest:@192.168.20.250/Volume_2 /Volumes/Volume_2
  1. #!/bin/bash
  2. mkdir /Volumes/Volume_1
  3. mkdir /Volumes/Volume_2
  4. /sbin/mount -t smbfs //guest:@192.168.20.250/Volume_1 /Volumes/Volume_1
  5. /sbin/mount -t smbfs //guest:@192.168.20.250/Volume_2 /Volumes/Volume_2

Code: [ Select ]
ESC

Code: [ Select ]
ZZ

Code: [ Select ]
chmod +X /mounts(dot)sh

Code: [ Select ]
chmod 700 /mounts(dot)sh

Code: [ Select ]
sudo defaults write com.apple.loginwindow LoginHook /mounts(dot)sh
  • canoncola
  • Born
  • Born
  • canoncola
  • Posts: 1

Post 3+ Months Ago

¡¡¡¡[SOLVED]!!!!

Didn't try the script posted up there but I DID try dlegend's "Login Items" method in System prefs and it DID NOT work..... (FOR ME)

I'm running 10.6.8 and trying to Automount TWO shares on my NAS

What I found WORKED is dragging an Alias that points to a folder on (each share) into my HOME FOLDER on my Mac.

When you login It automatically mounts each share.

Post Information

  • Total Posts in this topic: 26 posts
  • Users browsing this forum: No registered users and 2 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.