+ Post New Thread
Results 1 to 7 of 7
Mac Thread, LoginHook to map a couple of network drives in Technical; Can someone please give me a nice script i can use as a loginhook to map network drives on our ...
  1. #1

    Join Date
    Feb 2007
    Location
    Kent
    Posts
    634
    Thank Post
    271
    Thanked 51 Times in 43 Posts
    Rep Power
    40

    LoginHook to map a couple of network drives

    Can someone please give me a nice script i can use as a loginhook to map network drives on our new macs running 10.6

    It's driving me crazy!

    many thanks!

  2. #2
    dayzd's Avatar
    Join Date
    Nov 2009
    Location
    In front of computer
    Posts
    405
    Thank Post
    75
    Thanked 59 Times in 48 Posts
    Rep Power
    24
    What shares are you mapping - are they generic shared folders, or are they individual shares per user?

    The basic command for mapping a share in a bash script is as follows (and assumes you're using AFP filesharing):
    Code:
    #!/bin/bash
    
    # Create a mount point within the filesystem
    mkdir /Volumes/shareName
    # Mount the share to the mount point
    /sbin/mount -t afp afp://your.server/share /Volumes/shareName
    This will mount afp://your.server/share as a volume called shareName

    You'll also need a LogoutHook to unmount the share you added at login:
    Code:
    #!/bin/bash
    
    # Unmount share
    /sbin/umount /Volumes/shareName
    # Delete mount point used from file system
    rmdir /Volumes/shareName

    If you need to map a specific share for a user, LoginHook scripts are passed the current username as $1, so you can use this variable in the path if you require:
    Code:
    #!/bin/bash
    
    mkdir /Volumes/shareName
    /sbin/mount -t afp afp://your.server/$1 /Volumes/shareName
    This will mount afp://your.server/<username> as a volume called shareName


    If you need to use authentication you need to change your share address to something like this
    Code:
    #!/bin/bash
    
    mkdir /Volumes/shareName
    /sbin/mount -t afp afp://username:password@your.server/share /Volumes/shareName
    However, the above will only work if you want to use just one account to mount the share with. You can't have the user enter their password into a loginhook script as it runs. For example, I use the above method to mount a share during the login process to copy some files from the server, before disconnecting at the end of the login script, i.e.:
    Code:
    #!/bin/bash
    
    mkdir /Volumes/loginfiles
    /sbin/mount -t afp afp://serviceuseraccount:serviceuseraccountpassword@your.server/loginfiles /Volumes/loginfiles
    
    # File copying and other stuff happens here
    
    /sbin/umount /Volumes/loginfiles
    rmdir /Volumes/loginfiles

    Also, once you've written your *.sh script, you'll need to make it executable in the Terminal:
    Code:
    chmod +x yourscript.sh
    Hope this gets you started!

  3. #3

    Join Date
    Feb 2007
    Location
    Kent
    Posts
    634
    Thank Post
    271
    Thanked 51 Times in 43 Posts
    Rep Power
    40
    Thankyou, i have their user area mapping using the default options but wanted to map some generic student/staff shared areas too.

  4. #4

    Join Date
    Feb 2007
    Location
    Kent
    Posts
    634
    Thank Post
    271
    Thanked 51 Times in 43 Posts
    Rep Power
    40
    I created the script and made it executable ( or tried and it didn't complain) but when i double click, it just opens in texteditor.

    any ideas?

  5. #5

    Join Date
    May 2006
    Location
    West Bromwich
    Posts
    2,190
    Thank Post
    299
    Thanked 215 Times in 185 Posts
    Rep Power
    56
    Why using login hooks? Can you not just add the shares to the login items using WGM? This is how I mount staff data shares, pupil data shares and an applications share found on the windows server.

    Also you can mount afp shares using Kerberos authentication. Do man mount_afp for the command. I think that's what it is. It's been a while since I looked at this as it was easier using WGM.

  6. #6

    Join Date
    Feb 2007
    Location
    Kent
    Posts
    634
    Thank Post
    271
    Thanked 51 Times in 43 Posts
    Rep Power
    40
    I'm new to this. Didn't really matter how i did it, just needed to figure out how to achieve the end result.
    How would i go about adding my shares to the login items then?

  7. #7

    Join Date
    Feb 2007
    Location
    Kent
    Posts
    634
    Thank Post
    271
    Thanked 51 Times in 43 Posts
    Rep Power
    40
    Never mind! Easy peasy

SHARE:
+ Post New Thread

Similar Threads

  1. Map network drives on wireless network
    By woody in forum Windows
    Replies: 24
    Last Post: 1st December 2007, 06:27 PM
  2. Replies: 5
    Last Post: 26th November 2007, 06:40 PM
  3. Map network drives
    By netadmin in forum Scripts
    Replies: 17
    Last Post: 5th April 2007, 03:18 PM
  4. Map network drives
    By timbo343 in forum Scripts
    Replies: 7
    Last Post: 1st March 2007, 06:46 PM
  5. Replies: 7
    Last Post: 27th November 2006, 11:26 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •