Mount AFP volumes with shell script

Hi!

I have a shell scrip that works fine for the first volume, but that's it. How do I do to make it mount the other volumes as well?

The script looks like this:

#!/bin/bash
mkdir /Volumes/shares
mount_afp 'afp://name:password@10.130.130.254/System' /Volumes/shares
mount_afp 'afp://name:password@10.130.130.254/Images' /Volumes/shares
mount_afp 'afp://name:password@10.130.130.254/Images2' /Volumes/shares
exit 0
#

Thanks for helping out!

G4 Quicksilver 867 MHz, Mac OS X (10.4.7)

Posted on Aug 14, 2006 8:03 AM

Reply
7 replies

Aug 14, 2006 8:48 AM in response to star-affinity

Martin,

I'm not sure if this will apply at all to your predicament, but we've found that creating AppleScripts to mount volumes works best if we create individual scripts per mount.
This is certainly the case if we want to avoid any permissions problems when moving data BETWEEN mounted volumes.

As I've said, this may not apply to you, we're using A/S and are mounting CIFS volumes mostly, but the bottom line is that you might have to "granularise' the scripts, for the most reliability.

Best of luck! Paul

Aug 15, 2006 5:46 AM in response to Gary Kerbaugh

Martin,

Just to elaborate on Gary's response a little... mount_afp doesn't mount the share inside the mount point you specify, it mounts the share at the mount point you specify. So your script is trying to mount all three volumes at the same location in the file system. You need to create separate directories (mount points) for each of the shares. Something like this:

#!/bin/bash
mkdir /Volumes/share1
mkdir /Volumes/share2
mkdir /Volumes/share3
mount_afp 'afp://name:password@10.130.130.254/System' /Volumes/share1
mount_afp 'afp://name:password@10.130.130.254/Images' /Volumes/share2
mount_afp 'afp://name:password@10.130.130.254/Images2' /Volumes/share3
exit 0
#

HTH,
Steve

Aug 15, 2006 7:36 AM in response to star-affinity

Provided the Finder is running, you could just use applescript and let it handle everything:

#!/bin/bash

osascript -e "tell application \"Finder\" to mount volume \"afp://10.130.130.254/System\" as user name \" Username\" with password \" password\""

osascript -e "tell application \"Finder\" to mount volume \"afp://10.130.130.254/Images\" as user name \" Username\" with password \" password\""

osascript -e "tell application \"Finder\" to mount volume \"afp://10.130.130.254/Images2\" as user name \" Username\" with password \" password\""

exit 0
#

ThinkPad T60p Other OS

Aug 18, 2006 12:30 AM in response to star-affinity

Thanks guys for informing about not mounting all shares to the same mount point. However, that wasn't enough. I also had to add semicolon between the commands to make it work. Like this:

#!/bin/bash
mkdir /Volumes/shares_system
mount_afp 'afp://name:password@10.130.130.254/System' /Volumes/shares_system;
mkdir /Volumes/shares_images
mount_afp 'afp://name:password@10.130.130.254/Images' /Volumes/shares_images;
mkdir /Volumes/shares_images2
mount_afp 'afp://name:password@10.130.130.254/Images2' /Volumes/shares_images2
exit 0
#

Now the only thing I need is to make it run at startup. I've managed this by using the app Lingon.

I'll also try LittleSaint's suggestion using AppleScript.

Thanks again for your input!

G4 Quicksilver 867 MHz Mac OS X (10.4.7)

Aug 18, 2006 4:37 AM in response to star-affinity

Hi Martin,
It helps if you look up stuff that's suggested but I could see that you wouldn't know where to look for the osascript command. That's a UNIX utility that's used in the command line or in a shell script to embed AppleScript within it. As such, you can read about osascript with "man osascript". LittleSaint's commands work as is in the shell.

As an aside, LittleSaint's commands are excellent for mounting additional shares but aren't appropriate for mounting the share containing the home directory because the home directory is needed by the time the Finder is started in the user's new session. (I'm trying to set that up now) I'm having better luck with automounter but I can't seem to get it to authenticate with Kerberos. If anyone knows how to do that, I'm all ears.

One way to get the command run at the user's login is to create a LaunchAgent. I copied the /System/Library/LaunchDaemons/com.apple.KernelEventAgent.plist into the LaunchAgents directory and changed the filename and corresponding Label. The most important change is to change the ProgramArguments array to launch a shell script that mounts the extra shares. You can read about the syntax of this file in "man launchd.plist".

I should note also that I tried this to mount the share containing the home directory. Again, it doesn't run early enough in the login process to have a home directory ready when it was needed but it should work well for subsequent shares. Alternatively, you could put the AppleScript part of LittleSaint's osascript commands into an AppleScript, save it as an application and run it as a Login Item of the user.
--
Gary
~~~~
In the force if Yoda's so strong, construct a sentence
with words in the proper order then why can't he?

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Mount AFP volumes with shell script

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.