speeding_ant Posted January 17, 2011 Share Posted January 17, 2011 **** UPDATE **** macOS 10.12 Sierra breaks this script. I've developed an application to get around this issue. Available here: AutoMounter: https://itunes.apple.com/nz/app/automounter/id1160435653?mt=12 AutoMounter is a sleek and powerful menu item designed to automatically mount your network shares. - Supports SMB / AFP / NFS network shares - Supports multiple NAS appliances / servers - Server discovery - Persistent auto mounting of shares, when the server is reachable - Match a server to a WiFi Name (SSID) - Reacts to changes of network - Optionally send a Wake On LAN packet to a server when the network changes - Easy to use, unobtrusive, menu bar item - Optionally hide shares from Desktop - Resolves macOS Sierra authentication issue Thought I'd share my quick and simple bash script (with the help from Stokkes) for mounting AFP/SMB shares. Set your preferences, add the shares, and it will ping the server. If it is available then it will mount the shares. There is also an option to load iTunes at the same time. Now works with Lion. **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 You must have wolcmd (included) in the same folder as the script. This is a definable directory. If the server is unavailable via ping, WAKE is set to TRUE, and the time is within the hours specified, then the script will attempt wake on lan. You must have your server MAC address and subnet in the options. This is all shown in the script. Now if the server is unavailable it will exit iTunes. I found iTunes to be unstable if it can't resolve links to its music. You can set this in the script Step 1: Where to put mount.sh & com.media.mount.plist - Create a folder called "Scripts" on the root of your hard drive. This could be /Macintosh HD/Scripts. - Copy mount.sh to this folder. - Copy com.media.mount.plist to your user *Username*/Library/LaunchAgents folder. If the folder doesn't exist, create it. Step 2: Editing the mount script - Open mount.sh in text edit. Read the notes at the top of the script. - Enter your username and password inside the quotation marks where shown. Read the notes in the file if your password has symbols (eg @, as you'll need to url encode them). Site is given in the script. - Enter your server IP address (eg "192.168.0.100") and hostname (eg "tower") where shown. If your nas has a dynamic IP address (DHCP), enter the hostname instead of the IP Address. - Leave Mount point alone, unless you want the shares to mount somewhere other than the default /Volumes - Enter TRUE or FALSE if you want iTunes to open or not. - Enter the protocol you want to use, either smb or afp. - Enter the shares you want to mount. The shares must be space seperated (eg "TV Movies HD%20Movies". If the share name has a space in it, replace the space with %20 (eg "TV%20Shows"). Step 3: Enable script - Double check the settings are correct, and make sure the mount.sh, and com.media.mount.plist files are in the correct place. - Open Terminal (Applications/Utilities/Terminal). The sudo command will need your administrator password. Type: - sudo chown root:staff /Scripts/mount.sh - sudo chmod 775 /Scripts/mount.sh - Restart your computer. It should mount your shares on login, and check if they're mounted every one minute. If it's not working, double check permissions and settings. Try running the shell script by opening Terminal and typing: - /Scripts/mount.sh - Press enter If that works, then check the status of the launchd agent by going into Terminal and typing - launchctl list - This will display the loaded launch daemons. If there is a 1 next to the com.media.mount.plist file, make sure the script is located on your boot volume, "/Scripts/mount.sh". If it's not in the list at all, make sure that the plist in your user Library folder, in a folder called "LaunchAgents". Hope this is useful for someone! mount.zip Link to comment
Stokkes Posted January 17, 2011 Share Posted January 17, 2011 Always nice to see people adding custom scripts for Mac. Good job. Link to comment
speeding_ant Posted January 17, 2011 Author Share Posted January 17, 2011 Cheers! I've found a solution for quitting applications by their real names via terminal (not process ID, which tends to change often), and it will prompt to save documents first, or exit quietly. Unfortunately doesn't work with iTunes, as iTunesHelper daemon conflicts with the name. If you need this, let me know. You can also decide to umount Volumes if there server isn't available, where the else statement is. In the else statement (at the bottom) remove exit 0 and add umount /Volumes/Music etc. Link to comment
Stokkes Posted January 17, 2011 Share Posted January 17, 2011 I'll take a look at it when I get home this evening. I've been meaning to make a script that'll run on a set schedule (read: often) to make sure my volumes are still mapped. I often have an issue in Plex where the volumes get unmounted (either the Mini goes to sleep or something else happens) and I can no longer stream my media. I'm then forced to vnc into the mini and remap the drives manually.. PITA. So if this does what I've ben meaning to do, then fantastic. Link to comment
speeding_ant Posted January 17, 2011 Author Share Posted January 17, 2011 Exactly the reason why I made this script Also doesn't try and open the Volume in a window, like if you add the mounts to your login items. They just mount quietly in the background, and only if they're not mounted already and the server is on. Very useful if you run plex, or if you have iTunes running all the time, and your library is sitting on the shares. It runs every minute, so you're seldom left without your volumes mounted. Also, remember to put in the LaunchAgents folder in your user folder. If you use the main Library folder, it won't work. Link to comment
Stokkes Posted January 18, 2011 Share Posted January 18, 2011 Few potential problems I've seen with the script. I'm working on a slight modification. Long story short, there's a possibility that the shares mount correctly but are inaccessible because they are mounted by "root" Link to comment
speeding_ant Posted January 18, 2011 Author Share Posted January 18, 2011 I'm not having those issues. You need to run them from your user folder launch agents. If you run from the main Library Folder, it will run as root. There's no way around this as far as I could see. Link to comment
speeding_ant Posted January 18, 2011 Author Share Posted January 18, 2011 Here's screenshots of my setup. Link to comment
Stokkes Posted January 18, 2011 Share Posted January 18, 2011 I've actually quickly rewritten the script using your basic premise.. Try it out and let me know what you think.. (rename to .sh and chmod +x) Cheers, automount_unraid.txt Link to comment
speeding_ant Posted January 18, 2011 Author Share Posted January 18, 2011 Nice one - bit more polished now Move iTunes below the shares, otherwise will just spit errors when shares aren't mounted. Link to comment
Stokkes Posted January 18, 2011 Share Posted January 18, 2011 Updated.. I've actually written a quasi Microsoft DFS mounting script (seeing as it OSX doesn't have built-in DFS support) and learnt a lot about mounting shares from the command line. The password is truly a bugger, especially with symbols, etc. For example, the character "!" is a valid URL character and doesn't change during the url encode process, but wont' be accepted on the command line (have to change to %21). Very weird and frustrating Link to comment
speeding_ant Posted January 18, 2011 Author Share Posted January 18, 2011 Learning something every day! How long have you been in the business? Link to comment
Stokkes Posted January 18, 2011 Share Posted January 18, 2011 Oye... I've been in IT for about 16 years now. I do mostly management now, but still dabble in scripting, small-time programming. Link to comment
speeding_ant Posted January 18, 2011 Author Share Posted January 18, 2011 Only been in the scene for a couple of years now. Continual effort to keep learning, it's hard work! Have you tested the script yet? Just checked it out, something fishy with the loop for shares. It's creating folders called "echo" "if" etc, under /. Link to comment
Stokkes Posted January 18, 2011 Share Posted January 18, 2011 Yes I did and it works fine.. It's creating a folder called "echo" and "if"? Edit: Can you post your variable SHARES= & ROOT= lines? Link to comment
speeding_ant Posted January 18, 2011 Author Share Posted January 18, 2011 Yeah, random I'll look into it. Cheers Link to comment
speeding_ant Posted January 18, 2011 Author Share Posted January 18, 2011 Root is same "/Volumes" and shares I've just been testing with "Music Downloads" I'm actually getting parse errors on the comments. Something is up with the way my machine handles bash scripts... What version of OS X are you using? Cheers Link to comment
smoldersonline Posted January 18, 2011 Share Posted January 18, 2011 Gents, thank you so much for sharing this, extremely useful. Link to comment
speeding_ant Posted January 18, 2011 Author Share Posted January 18, 2011 No worries! Stokkes did a better job though... Did you manage to get Stokkes script to work? I tried again, but have issues running it on 10.6.6 client and server. Very strange Link to comment
smoldersonline Posted January 18, 2011 Share Posted January 18, 2011 Works fine here (10.6.6) using the hostname. Don's know why, but I couldn't get it to work using the server's IP. edit: strange, on my Plex Mac mini (running 10.6.4) it's just the other way around, hostname doesn't work and IP does... I have some trouble to get it to mount my "TV Shows" user share. TV+Shows should work? Link to comment
speeding_ant Posted January 18, 2011 Author Share Posted January 18, 2011 Try TV%20Shows If you're running your own DNS server, it should work with hostname. If not, then stick with the IP. Link to comment
smoldersonline Posted January 18, 2011 Share Posted January 18, 2011 Tried TV%20Shows, no luck... Link to comment
speeding_ant Posted January 19, 2011 Author Share Posted January 19, 2011 I rewrote my script with some of Stokkes code, added in option for AFP mounts, and now spaces should work. Read notes in file first. File re-uploaded in first post. Link to comment
smoldersonline Posted January 19, 2011 Share Posted January 19, 2011 Thanks again! It works fine if I don't include a share with a space. Including TV%20Shows results in the following: line 47: TV%20Shows: command not found and neither of the shares (on with, one without a space) specified will mount. Link to comment
speeding_ant Posted January 19, 2011 Author Share Posted January 19, 2011 Which script are you using? Can you attach your modified script (sans username/password of course) so I can check it out? I've got a few shares with spaces, works sweet with me. Cheers Link to comment
Recommended Posts
Archived
This topic is now archived and is closed to further replies.