macOS users - AutoMount your Shares


Recommended Posts

Is there a way to mount the afp shares with read and write permission for all administrative users? As of now only the user that runs the script gets to read the volumes.

 

Current this is a 'per user' script. Network filesystems work in strange ways in Mac OS X, with AFP/SMB sessions 'attaching' themselves to a particular UID once accessed.

 

You could experiment using autofs...  can't guarantee that will solve your problem though.

 

Why not just manually implement this script on all administrative users?

Link to comment
  • Replies 232
  • Created
  • Last Reply

Top Posters In This Topic

...

 

Why not just manually implement this script on all administrative users?

 

I think that'll cause problems with fast user switching.

I'm currently using a automount solution but that has the same problem; the first user to access the volume sets the mode to 700. Frustrating...

 

I'll keep an eye out here it someone finds a good solution.

 

/Erik

Link to comment

What about mounting the volumes to somewhere other than /Volumes? Modification of the script to use the username as a variable to mount at /Volumes/username/Share, or change the mount command to mount onto the desktop directly (~/), and use flag nobrowse to prevent it from showing up in Finder.

 

I tried the automount way and mounting the shares in /Users/Shared/servers and got the exact same issue, the first user to access the share made it it's share, example erik:staff and mode 700 which ment it became inaccessible for other users within the staff group.

Is it possible to mount the same shares in different locations? (Not necessarily with your script)

Ex)

mount_afp afp://user:[email protected]/Public /Users/user1/shares

mount_afp afp://user:[email protected]/Public /Users/user2/shares

Link to comment

What about mounting the volumes to somewhere other than /Volumes? Modification of the script to use the username as a variable to mount at /Volumes/username/Share, or change the mount command to mount onto the desktop directly (~/), and use flag nobrowse to prevent it from showing up in Finder.

 

I tried the automount way and mounting the shares in /Users/Shared/servers and got the exact same issue, the first user to access the share made it it's share, example erik:staff and mode 700 which ment it became inaccessible for other users within the staff group.

Is it possible to mount the same shares in different locations? (Not necessarily with your script)

Ex)

mount_afp afp://user:[email protected]/Public /Users/user1/shares

mount_afp afp://user:[email protected]/Public /Users/user2/shares

 

Not sure... give it a go!

 

Use different usernames and passwords, as mount commands use an existing session if available.

Link to comment
  • 2 weeks later...

Problems

 

I created a folder called shares in /Users/myuser

 

Edited the script to mount in '/Users/myuser/shares/'

 

It seems as if I have to manually delete the content of /Users/myuser/shares/ for the script to mount the shares again - the folders from prior mounting causes problems.

 

/Users/myuser/shares has mode 700 and owner myuser:staff and the same goes for the folders the script creates when mounting the shares.

 

"Mount already exists" but it's just empty folders.

 

How come?

Link to comment
  • 1 month later...

Hi,

 

I am struggling getting this script working.

 

When I run '/Scripts/mount.sh' I get the result below. What does this mean, and what have I done wrong to cause this error?

 

Thanks

 

Simons-MacBook-Pro:~ simonosborne$ /Scripts/mount.sh

/Scripts/mount.sh: line 84: edit: command not found

usage: ping [-AaDdfnoQqRrv] [-b boundif] [-c count] [-G sweepmaxsize]

            [-g sweepminsize] [-h sweepincrsize] [-i wait] [?k trafficclass]

            [-l preload] [-M mask | time] [-m ttl] [-p pattern]

            [-S src_addr] [-s packetsize] [-t timeout][-W waittime] [-z tos]

            host

      ping [-AaDdfLnoQqRrv] [-b boundif] [-c count] [-I iface] [-i wait]

            [?k trafficclass] [-l preload] [-M mask | time] [-m ttl] [-p pattern] [-S src_addr]

            [-s packetsize] [-T ttl] [-t timeout] [-W waittime]

            [-z tos] mcast-group

/Scripts/mount.sh: line 191: [: ==: unary operator expected

/Scripts/mount.sh: line 205: [: ==: unary operator expected

/Scripts/mount.sh: line 216: [: ==: unary operator expected

Simons-MacBook-Pro:~ simonosborne$

Link to comment
  • 1 month later...

Hi,

 

I am struggling getting this script working.

 

When I run '/Scripts/mount.sh' I get the result below. What does this mean, and what have I done wrong to cause this error?

 

Thanks

 

Simons-MacBook-Pro:~ simonosborne$ /Scripts/mount.sh

/Scripts/mount.sh: line 84: edit: command not found

usage: ping [-AaDdfnoQqRrv] [-b boundif] [-c count] [-G sweepmaxsize]

            [-g sweepminsize] [-h sweepincrsize] [-i wait] [?k trafficclass]

            [-l preload] [-M mask | time] [-m ttl] [-p pattern]

            [-S src_addr] [-s packetsize] [-t timeout][-W waittime] [-z tos]

            host

      ping [-AaDdfLnoQqRrv] [-b boundif] [-c count] [-I iface] [-i wait]

            [?k trafficclass] [-l preload] [-M mask | time] [-m ttl] [-p pattern] [-S src_addr]

            [-s packetsize] [-T ttl] [-t timeout] [-W waittime]

            [-z tos] mcast-group

/Scripts/mount.sh: line 191: [: ==: unary operator expected

/Scripts/mount.sh: line 205: [: ==: unary operator expected

/Scripts/mount.sh: line 216: [: ==: unary operator expected

Simons-MacBook-Pro:~ simonosborne$

 

I came across this issue last night and happened upon this thread so I figured I'd throw you a bone.

 

I think it comes down to TextEdit just being an awful option for editing code. The machine I was editing the script on didn't have anything else, so I used TextEdit. I got the same error as you. Then I installed SublimeText, opened the script, and noticed the syntax highlighting was all screwed up after a certain line.

 

TL;DR: TextEdit inserted smart quotes. Go through all the areas where you might have modified an option (e.g. "Do you want iTunes open?") and make sure there are plain double quotes (") instead of fancy double quotes (”). Script runs perfectly after you fix that.

Link to comment
  • 2 months later...

Where can I get the latest version of this script with the change described in the first post on 28/12/2012?

 

**NEW** Added functionality to wake the server via WOL **NEW**

28/12/2012 - Added the ability to call "wake" at the end of the script to wake the server, no matter which time it is. eg: /scripts/mount.sh wake

 

When I click on the link in the first post to download the script, the resulting file is dated Dec. 27, 2011 and does not seem to include this added functionality.

 

Thanks in advance.

 

 

Link to comment
  • 2 months later...
  • 2 months later...

Using it with iTunes 12.3 without issue (on Yosemite and El Capitan).

 

I noticed a small bug with the script. In case you'd not want to open iTunes automatically but you'd want to close it in case the network is not available the section of code

 

# Opens iTunes if TRUE and Server 
if [ $ITUNES == "TRUE" ] && [ $AVAILABLE == "TRUE" ]; then

if (! ps ax | grep -v grep | grep -v iTunesHelper | grep /Applications/iTunes.app/Contents/MacOS/iTunes > /dev/null ); then

echo "Attempting to open iTunes"
open /Applications/iTunes.app/

fi

else

if [ $ITUNESQUIT == "TRUE" ]; then

echo "Attempting to close iTunes"
osascript -e 'tell application "iTunes" to quit'

fi

fi

 

will not work properly, in fact you need to add a condition to the second nested if

 

# Opens iTunes if TRUE and Server 
if [ $ITUNES == "TRUE" ] && [ $AVAILABLE == "TRUE" ]; then

if (! ps ax | grep -v grep | grep -v iTunesHelper | grep /Applications/iTunes.app/Contents/MacOS/iTunes > /dev/null ); then

echo "Attempting to open iTunes"
open /Applications/iTunes.app/

fi

else

if [ $ITUNESQUIT == "TRUE" ] && [ $AVAILABLE == "FALSE" ]; then

echo "Attempting to close iTunes"
osascript -e 'tell application "iTunes" to quit'

fi

fi

 

 

Link to comment

Working perfectly on Yosemite and El Capitan, just what I was looking for for my Plex

 

I couldn’t get it to work at first until I edited the script with SublimeText, thanks to burnedpixel, TextEdit was screwing up the script. Also I couldn't get com.media.mount.plist to work until I select Get Info and change the Sharing & Permissions to read only for staff and everyone, keep user to read&write

 

Here is my setup

 

# Script Location

SCRIPTLOCATION="/Scripts"

 

# Username for server

USERNAME="NASusername"

 

# Password for server, check notes

PASSWORD="password"

 

# IP Address/hostname for ping

PING="192.168.1.1"

 

# Hostname for server. Try sername.local, hostname or IP

HOSTNAME="Nas.local"

 

# Protocol in lowercase, afp or smb

PROTOCOL="afp"

 

# Shares, check notes

SHARES="Music Plexdrive"

 

 

 

Link to comment
  • 4 weeks later...

Sorry if this has been answered before (or perhaps common knowledge here)...but does using/utilizing this script keep shared network drives from hibernating?  I have a Synology NAS and need to be able to have the disks hibernate when not in use but if this script wakes them each time it runs then I may have to look elsewhere.  Thanks.

Link to comment
  • 1 month later...

I gave up and re-imported all my iTunes files and the old mount files off the old drive. Put everything in place and iTunes opened right up and I've been playing music uninterrupted since.  Love this!  Thanks again for everyone's efforts on this.

 

Hoping someone can provide some guidance.  I was running this successfully for the last few years, including after an upgrade to El Capitan.  Recent problems with my macbook resulted in a trip to the Genius bar and a recommendation to perform a clean install.  I installed a new SSD, performed a clean install of 10.11, and have been trying to manually restore all my settings/files versus a TM backup to ensure everything is clean.  I've been successful so far, except for getting this working.  I saved an old copy of my mount.sh file and used it to populate a new fresh copy downloaded from the original post (used TextWrangler).  I've read through this entire thread, and still can't get it to work.  Included is a copy of my mount.sh file. 

 

1) Create a folder called "Scripts" on the root of your hard drive, and copied mount.sh to /Macintosh HD/Scripts

2) Created LaunchAgents folder and copied com.media.mount.plist to *Username*/Library/LaunchAgents folder.

3) Terminal entry:

    - sudo chown root:staff /Scripts/mount.sh

    - sudo chmod 775 /Scripts/mount.sh

4) Restart

5) From a fresh restart, if I run /Scripts/mount.sh from Terminal, I get the following:

6) I have finder preferences set to show shared connected servers and see Tower.  Clicking on it all, all my shares are available.  Clicking on "Music" mounts the drive, and it shows up on the desktop since finder preferences is set to show connected servers on the desktop.    If I rerun /Scripts/mount.sh, I get:

I'm confused since the share will mount through the finder, but not the script.  Additionally, when I open iTunes my library is viewable, however I can only play 45 seconds of a track before iTunes shuts down.  Any help would be greatly appreciated.

Link to comment
  • 3 months later...

I've been trying to get this to work without any luck.

OS= 10.11.3

 

When I restart my computer nothing mounts. If i try to run mount.sh manually I get this-

maggie:~ wgstarks$ /Scripts/mount.sh 
PING 10.0.1.20 (10.0.1.20): 56 data bytes

--- 10.0.1.20 ping statistics ---
5 packets transmitted, 5 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 0.205/0.358/0.432/0.090 ms
Mounting flash ...
mount_smbfs: URL parsing failed, please correct the URL and try again: Invalid argument
flash mount failed. Check settings/server. Removing mount point.
*************
Mounting Media ...
mount_smbfs: URL parsing failed, please correct the URL and try again: Invalid argument
Media mount failed. Check settings/server. Removing mount point.
*************
Attempting to close iTunes

 

I've attached a copy of mount.sh

mount_copy.sh.zip

Link to comment

This is some thing iv'e been looking for, Fantastic!

 

But, when i add more than one share i get this:

PING 10.0.1.137 (10.0.1.137): 56 data bytes

--- 10.0.1.137 ping statistics ---
5 packets transmitted, 5 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 1.485/1.601/1.664/0.061 ms
Mounting Gringotts appdata ...
mount_smbfs: mount error: /Volumes/Gringotts appdata: Unknown error: -1073741275
Gringotts appdata mount failed. Check settings/server. Removing mount point.
*************

 

I did the %20 part in the share section

# Shares, check notes
SHARES="Gringotts%20appdata"

Link to comment

This is some thing iv'e been looking for, Fantastic!

 

But, when i add more than one share i get this:

PING 10.0.1.137 (10.0.1.137): 56 data bytes

--- 10.0.1.137 ping statistics ---
5 packets transmitted, 5 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 1.485/1.601/1.664/0.061 ms
Mounting Gringotts appdata ...
mount_smbfs: mount error: /Volumes/Gringotts appdata: Unknown error: -1073741275
Gringotts appdata mount failed. Check settings/server. Removing mount point.
*************

 

I did the %20 part in the share section

# Shares, check notes
SHARES="Gringotts%20appdata"

Since you say "More than one share" I'm making a guess that maybe this is two shares? If so, the code should read Gringotts appdata. The %20 is only used to replace spaces in the name of the share. Is the actual name of the share Gringotts appdata?

Link to comment

This is some thing iv'e been looking for, Fantastic!

 

But, when i add more than one share i get this:

PING 10.0.1.137 (10.0.1.137): 56 data bytes

--- 10.0.1.137 ping statistics ---
5 packets transmitted, 5 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 1.485/1.601/1.664/0.061 ms
Mounting Gringotts appdata ...
mount_smbfs: mount error: /Volumes/Gringotts appdata: Unknown error: -1073741275
Gringotts appdata mount failed. Check settings/server. Removing mount point.
*************

 

I did the %20 part in the share section

# Shares, check notes
SHARES="Gringotts%20appdata"

Since you say "More than one share" I'm making a guess that maybe this is two shares? If so, the code should read Gringotts appdata. The %20 is only used to replace spaces in the name of the share. Is the actual name of the share Gringotts appdata?

 

I misunderstood the guide, thought it was the other way around, so tried with a space instead og %20 and it didn't work, so i realized that the share "appdata" was AFP only, tried with another share ant with th space and it worked.

 

So n00b mistake of misreading the guide. Thanks for the quick support :)

Link to comment

Mind if I ask what OS your using on your Mac? I can't get mine working with El Capitan and SMB shares.

 

I'm on El Capitan (10.11.13) both SMB and AFP working.

 

How did you edit the mount.sh?

First i edited it in textEdit but it didn't work, so downloaded it again and edited it in terminal with nano.

Link to comment

I edited with TextWrangler (BBEdit lite). Much better than TextEdit. I don't think that's the problem but I could try nano. Can you describe the process to edit?

 

Re-download and replace the mount.sh go to terminal, and:

$ nano /Scripts/mount.sh 

 

Edit so the settings mach what you got, and when you are done pres ctrl + x, the y for yes and enter to confirm and exit.

Link to comment

Success. Wasn't anything wrong with the text editing. Totally user error. When I opened the file in terminal it displayed the instructions over and over.

# PASSWORD: If your password contains symbols, they must be url encoded      #

#          ie: "@" becomes "%40". To encode your password, use this site:    #

#          http://www.opinionatedgeek.com/dotnet/tools/urlencode/Encode.aspx  #

I really should read the instructions first. :D

 

BTW- If you want a good substitute for TextEdit you should checkout TextWrangler. Free and very versatile.

 

Thanks for the help.

Link to comment

Success. Wasn't anything wrong with the text editing. Totally user error. When I opened the file in terminal it displayed the instructions over and over.

# PASSWORD: If your password contains symbols, they must be url encoded      #

#          ie: "@" becomes "%40". To encode your password, use this site:    #

#          http://www.opinionatedgeek.com/dotnet/tools/urlencode/Encode.aspx  #

I really should read the instructions first. :D

 

BTW- If you want a good substitute for TextEdit you should checkout TextWrangler. Free and very versatile.

 

Thanks for the help.

 

Well it helps to read the instructions, and read them right  :P

 

Thanks for the tip!  :D

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.