Go Back   The macosxhints Forums > OS X Help Requests > UNIX - General



Reply
 
Thread Tools Rating: Thread Rating: 6 votes, 5.00 average. Display Modes
Old 04-05-2009, 09:12 PM   #1
weboweb
Prospect
 
Join Date: Apr 2009
Posts: 2
Mount AppleShare volume on bootup (not login)?

I am trying to mount an appleshare volume at boot time (not login time) by storing the commands in /etc/rc.local, but I am having some problems. If I have the following commands in rc.local, the device mounts okay, but it's mounted as root so my other software can't access it:
Code:
#  /etc/rc.local

mkdir /Volumes/my_mount_point
mount_afp afp://user:pass@192.168.0.2/folder /Volumes/my_mount_point
So I tried to run the commands by sudoing to the user I needed it to be mounted under, like this:

Code:
#  /etc/rc.local

sudo -u sysadmin mkdir /Volumes/my_mount_point
sudo -u sysadmin mount_afp afp://user:pass@192.168.0.2/folder /Volumes/my_mount_point
But the mount_afp command would fail, with the following error (from /var/log/system.log):


Code:
# /var/log/system.log

myhostname sudo[141]:	root : TTY=unknown ; PWD=/ ; USER=sysadmin ; COMMAND=/sbin/mount_afp afp://user:pass@192.168.0.2/directory /Volumes/my_mount_point

com.apple.SystemStarter[51]: mount_afp: AFPMountURL returned error -1069 errno is -1069
error 1069 apparently occurs when the device to be mounted cannot be found, but it's definitely there, and if I run the mount_afp command when logged in as sysadmin, it works.

Does anyone have any ideas? Can I just mount it as root and then chown to sysadmin? I tried adding chown sysadmin -R /Volumes/my_mount_point to the first script, but it failed.

I am running out of ideas given my limited experience with unix, and apple's extensions to it. Any help, even a poke in the right direction, would be much appreciated.


P.S: I have previously posted this question at macrumors but I don't think anyone's going to respond (link).
weboweb is offline   Reply With Quote
Old 04-08-2009, 09:35 PM   #2
BjarneDM
Prospect
 
Join Date: Jul 2007
Posts: 32
I'ld forget everyting about rc.local - Apple has deprecated the rc.* files.

Apple are advising to go the launchd route, so the solution I'm presenting to you here will go that route.

In your case you'll need two files: a plist and a script

The plist should look something like this:
Code:
bash-4.0# cat /Library/LaunchDaemons/info.mathiesen.mountafp.plist 
<?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>EnableGlobbing</key>
	<true/>
	<key>Label</key>
	<string>info.mathiesen.mountafp</string>
	<key>ProgramArguments</key>
	<array>
		<string>~bjarne/System/sbin/mountafp</string>
	</array>
	<key>RunAtLoad</key>
	<true/>
	<key>UserName</key>
	<string>bjarne</string>
</dict>
</plist>
and the script something like this:
Code:
bash-4.0# cat mountafp 
#!/bin/bash

mkdir /Volumes/mountpnt
mount_afp afp://[user[;AUTH=uamname][:password]@]host[:port]/volume /Volumes/mountpnt
I'm assuming you'll be able to modify the above according to your own situation

You start things by executing this command as root:
Code:
launchctl load -w /Library/LaunchDaemons/info.mathiesen.mountafp.plist
The man pages for launchd, launchd.plist and launchctl ought to enlighten you as to what I'm up to

Incidentially, the plist must be owned by root:wheel, and remember to chmod +x the script

I've tested it on my own iMac and it works as advertised
BjarneDM is offline   Reply With Quote
Old 04-11-2009, 07:35 AM   #3
weboweb
Prospect
 
Join Date: Apr 2009
Posts: 2
Thank you BjarneDM. I have followed your recommendation, but unfortunately even with the new approach I am still getting error -1069 from mount_afp (and yet, if I enter the mount_afp commands over a terminal, they work fine).

I am beginning to think that the network interface might not be up when my script is running (as the volumes to be mounted are on the network).
weboweb is offline   Reply With Quote
Old 04-14-2009, 01:00 PM   #4
BjarneDM
Prospect
 
Join Date: Jul 2007
Posts: 32
OK - then lets try this:

Code:
bash-4.0# cat mountafp 
#!/bin/bash

until ping -c2 -t5 [host] >/dev/null 2>&1
do
    sleep 5
done

mkdir /Volumes/mountpnt
mount_afp afp://[user[;AUTH=uamname][:password]@]host[:port]/volume /Volumes/mountpnt
BjarneDM is offline   Reply With Quote
Old 04-14-2009, 01:25 PM   #5
tlarkin
League Commissioner
 
Join Date: Mar 2003
Location: Bay Area, CA
Posts: 11,351
I had a similar problem but it was due to the fact that my AFP shares were on old Novell servers that only supported plain text passwords. I also ended up using an Apple Script that invoked shell scripting in the script. For some reason, mount_afp gave me a lot of trouble, here is an example of my script:

Code:
tell application "Finder"
	
	mount volume "afp://user:passwd@sevrer.domain.com/sharepoint"
	
	delay 10
	repeat 25 times
		if (exists "sharepoint") then
			do shell script "open -a desired.app"
			exit repeat
			
		end if
		delay 2
	end repeat
end tell
My script was to automate a network share mapping and then launch an application that needed that database file on that network share. For some reason I could never get mount_afp to work nor could I get tell finder to activate application to work in conjunction with each other.

I ended up using apple script for the mounting and then shell commands for the app launching and it works. I have no idea why, maybe a lack in the API or something?
__________________
sudo make me a sammich

http://www.tlarkin.com

"It just told me what I already knew, that I'm a great and amazing guy, didn't I tell you baby, I'm Zaphod Beeblebrox."
tlarkin is offline   Reply With Quote
Old 05-02-2012, 05:37 PM   #6
fwpGreg
Prospect
 
Join Date: Oct 2003
Posts: 4
I did this years ago for something, and just again needed to do it, but my notes were inadequate. After a lot of fiddling and trying everything in posts like this one I finally got it to work. I've written enough details out so that I'll never have to do that again (I hope).

So, yes, you can combine launchd and a script to have an automated mounting without a login, but there's some details that many other posts fail to mention -- like difference between mounting an AFP volume vs a share point. Also, what happens if the share point unmounts? The launchd/script should handle that.

All the nitty gritty details are here (way too much detail for a direct post):

http://www.gregwillits.ws/articles/u...t_upon_startup
fwpGreg is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 03:31 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.