At 16:04 -0400 5/1/02, [EMAIL PROTECTED] wrote:
>While we're on the subject of remote volumes, I've been trying to figure out
>how to automate mounting "normal" AFP volume from Perl (or the Terminal --
>it just has to let Perl read & write files) in OS X. The servers require ID
>& password.
Just use "mount -t afp" with an AFP URL, which calls "mount_afp" to
do the actual mount:
[adampb:~] adam% mount_afp
usage: mount_afp [-o option1[,option2...]]
afp://[username:password]@rhost[:port]/volume node
There are some catches, though.
First, it doesn't create the node for you. You have to do it
yourself. So you'll usually use something like this:
% mkdir /Volumes/myshare
% mount -t afp afp://adam:[EMAIL PROTECTED]/myshare /Volumes/myshare
[ do stuff ]
% umount -f /Volumes/myshare
% rmdir /Volumes/myshare
This logs into myserver.example.com with username "adam", password
"mypass", and mounts the sharepoint "myshare" at /Volumes/myshare.
Then it unmounts it and removes the directory. Of course, you don't
have to mount in /Volumes like the automounter does -- you can put it
anywhere.
Another catch is that mount_afp has no error reporting, so if you
fail to log in for whatever reason (bad password, bad username, no
access to that sharepoint, server down, etc.), it fails silently.
You'll have to cd into the mounted sharepoint and look at the files
there to see if it succeeded. You can also look at the output of
"mount" and see if there's a mount of type "afp_X..." on the
mountpoint you designated.
Another catch is that the Finder isn't notified of this mount, so
you'll have to use "Go to Folder" and go to /Volumes/myshare for the
Finder to see it. (Or use "open /Volumes/myshare".) If you don't
care about the Finder and are just running scripts or other
command-line stuff, this isn't a big deal.
Yet another catch is that if you mount a volume this way, the Finder
can't unmount it -- it'll always say that the volume is in use. You
have to use "umount -f" to force it to unmount, which logs out of the
AFP server. Again, not a big deal if you don't care about the Finder.
Lastly, you should use "mount -t afp" instead of directly calling
"mount_afp" if you can. Someday, the functionality of mount_afp may
be folded into mount, and mount_afp may go away. If you're using
"mount -t afp", you won't have to change all your scripts when that
happens.
adam
--
--
Adam Wells <[EMAIL PROTECTED]>
Mac OS X Server QA
Apple Computer