shell script to mount smb shares

i currently use an app that auto-mounts some network share folders at login. i know i don't need an app and mac os can auto-mount them if i add them to login items. but the reason i use the app is to control login credentials for each share as well as have some additional controls over share mounts available in the GUI of the app.


i prefer to move away from using this app and want to create scripts for auto mounting the shares upon login. i prefer shell script, but can also do applescript if anyone is knowledgable with how it should be written ?


some advice on how to setup a script to do that would be greatly appreciate. thanks in advance


i am using Big Sur 11.6.3.

MacBook Pro 16″, macOS 11.6

Posted on Feb 4, 2022 9:55 AM

Reply

Similar questions

9 replies

Feb 5, 2022 6:04 PM in response to zero7404

First, the advantage of putting an Alias for the mounted SMB mount, is that you can store the credentials in your keychain, and not have to expose any of that in a script.


Basically mount the SMB volume, Create an Alias of the mount point. Put the Alias in your Startup Items. The first time you mount the SMB volumes you will be prompted for the credentials. At that time you can approve putting the credentials in your keychain. After that it should just get the credentials from your keychain. If you need to mount the SMB volumes independent from logging in, you can just double click on the alias.


EtreSoft has also made a very good suggestion to look at auto mount.


If you really want to write a script, then look at the 'open' command

open smb://workgroup;username:password@server.address/sharename

workgroup; is optional

username is optional

username:password is optional

@ only needed if you specify any of the other stuff before the @

Feb 5, 2022 6:27 PM in response to BobHarris

thank you BobHarris for that .... i was issuing the command wrong


assuming a share is not mounted, issuing this command you posted will mount it and create the mount point in /Volumes ?

shell script 'open' method does not rely on keychain, if i specify the username:password directly in the line ... ?


i was looking to avoid doing this with login/startup items. the list in login items does not respect the order of the items listed. it just executes them 'whenever'. if i use a shell script, it runs the commands in order of how they are listed, which is nice when you want the shares to open as tabs in your finder in a certain order. i would not be exploring this option if finder would remember my open tabs on external volumes, or allow me to arrange startup items in the order i want them to execute. i created an app with automator that has the shell scripts execute 1 by 1, where each one calls on opening a share in finder, which creates the tab where i want to see it. easy to navigate finder when you know exactly where the tab to the path you want is always in the same place.


i was using the mount command to do this and it appeared to work, but the share was not appearing in /Volumes. it was there, because an 'ls -al' put up a message saying "access denied ... /Volumes/sharename" -- i don't recall the entirety of the line ls printed. but that line applied to the share i tried with 'mount'. and it was not shown in the ls output.

Feb 5, 2022 6:32 PM in response to etresoft

thanks for this tip, but i don't know what Automount is, technically. is it some framework in mac OS ?


i lucked out some time ago and found a freeware app called Connect Me Now. pretty nifty tool with lots of options for mounting shares. for the most part works well, except sometimes it hiccups, forgets a share path and it doesn't mount. recently all my shares dropped completely out of nowhere but that was a 1-off.


i can't have that concern when i have automated syncrhonizing apps launching and copying data to smb shares ... if that happened during the job, that could corrupt the destination data. not sure if it would corrupt the source data residing on the mac.

Feb 5, 2022 6:39 PM in response to BobHarris

would it do the same thing as 'open' directly to the smb share ? silently without opening any finder windows ?


by default finder windows open when the share mounts at startup, but this app i use 'Connect Me Now' is doing it silently without new finder windows or tabs. i prefer to run another script to open the folder paths in sequence in finder after the mount event.


to avoid confusion, i just want to do the following with a shell script:


mount smb shares 1, 2, 3, 4, 5

wait a few seconds to ensure they're all mounted

open individual finder tabs for the share paths i use often


sorry if i'm making it confusing or complex sounding and thank you for helping me with this

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.

shell script to mount smb shares

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