Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Mount smb server 'tree'

Hi there, I have some smb file servers (about 10) that I want to mount in a folder structure by running a script.

To make it visual:

/Volumes/company/management         - smb://fileserver1/mgmnt
/Volumes/company/Video
/Volumes/company/Video/public       - smb://fileserver2/public_video
/Volumes/company/Video/internal     - smb://fileserver1/internal_video
/Volumes/company/projects
/Volumes/company/projects/A         - smb://fileserver3/A
/Volumes/company/projects/B         - smb://fileserver3/B

(Obviously, I got a list of folder path and corresponding server shares to start from.)


The user will have to log in with his/her/it's user credentials and it would make sense if the user only has to enter these details once when running the script.


The first step to automating is doing it manually. While doing so, I noticed that if I 'connect to server..' from within Finder I'm asked for credentials once: on my first file server. When I connect to another server, osx seems to try the credentials it already has and it can connect to the second server without asking for a password again. This also works from AppleScript with


tell app "finder" to mount volume "smb://fileserver1/shareA"
tell app "finder" to mount volume "smb://fileserver2/shareB"


Unfortunately this lacks mount destination.


The only way I found for setting the mount destination is from bash with variants of mount/mount_smbfs that require a username and password to be entered for each and every one of them:

mount_smbfs //user:pass@filerserver1/shareA /Volumes/company/folderA


Any idea how I can get the best of both worlds?


Thanks!

Posted on Apr 26, 2019 3:23 AM

Reply

Similar questions

19 replies

May 21, 2019 5:28 AM in response to rccharles

Hi @rccharles,


The script is working fine. Thanks.


I still have an issue though, something somewhat related. I found out I can ask for user credentials with finder mounting a volume such as smb://*:*@server/share. After the user has filled that form out, shares mounted with mount_smb will use the same credentials. This means I don't have to make symlinks anymore. I can simply create the mounts 'in place'. One small downside: it replaces the original mount directory names with the share name. This is a common issue apparently.


I noticed you commented on a similar topic a long time ago: https://discussions.apple.com/thread/4895793 Now, I was wondering if you have any new information/insights on this. The way I see it, Finder has to store this 'overlay' name somewhere. I hardly doubt it will perform the equivalent of finding the mount point, reading the share and retrieving the basename part of it every time the folder is accessed. I also doubt this is kept in memory, as USB sticks can be renamed and those names stick around even after a reboot. But I haven't got a clue on where to start my search for the actual file..

May 17, 2019 3:55 PM in response to mdirickx

Ok, I understand their on there own machine and you want to simplify things for the user.



But they are not discouraged by:


mac $ pwd
/Users/mac
mac $ ls -ld videotest/
dr-x------  5 mac  staff   170B May 17 18:38 videotest//
mac $ ls -l videotest/
total 0
-rw-r--r--  1 mac   staff     0B Apr 19 19:25 echo
-r-x------  1 root  staff     0B May 17 18:35 one*
-r-x------  1 root  staff     0B May 17 18:35 two*
mac $ 

and there not discouraged by the subsequence message that they will not be able to see it again?



May 21, 2019 5:23 PM in response to rccharles

to see what files are open in the finder you can look in /Applications/Utilities/Activity Monitor



click on disk.


I guess these are currently open with no history.


Look for recently changed files ( maybe it includes accessed. I don't know. )



example output.



My first place to look would be keychain.


--------------------------------

The ultimate would be to get the fslogger program. You can use it to track what an app does.

Be sure to get the correct version of the program.


I discovered a new toy.

fslogger

http://osxbook.com/software/fslogger/

This command line program finds the same files as Spotlight indexes.

Macintosh-HD -> Applications -> Utilities -> Terminal

cd /Applcations/fslogger
mac $ sudo ./fslogger
fsevents device cloned (fd 5)
fslogger ready
      ... clipped ...
# Event
  type           = FSE_CONTENT_MODIFIED
  pid            = 233 (firefox-bin)
  # Details
    # type           len  data
    FSE_ARG_VNODE     85  path   = /Users/mac/Library/Application Support/Firefox/Profiles/Default User/sessionstore.js
    FSE_ARG_DEV        4  fsid   = 0xe00000c
    FSE_ARG_INO        4  ino    = 2444670
    FSE_ARG_MODE       4  mode   = -rw-r--r--  (0x0081a4, vnode type VREG)
    FSE_ARG_UID        4  uid    = 1000 (mac)
    FSE_ARG_GID        4  gid    = 20 (staff)
    FSE_ARG_DONE (0xb33f)



You need to run it in the terminal.


Macintosh-HD -> Applications -> Utilities -> Terminal


# The sudo command will ask for your administration password. No characters will appear when typing your password. Press return when done typing. sudo stands for super user do. It's just like root. Be careful.


sudo ./fslogger




May 17, 2019 2:34 AM in response to etresoft

Hi @etresoft,


Yes, it's an AD DFS server that I'm duplicating. The osx laptops are not part of the domain, so I can't use kerberos. The only other option I have to use autofs is to hardcode the server's user and password and I don't want that. The idea is that a lot of people come into this documentary studio for just a couple of days. Mounting the DFS share directly is not reliable enough when they are rendering something (for hours and hours), autofs works on the company owned stations but is too intrusive for the day flies. Best thing I can think of is a script run with user permissions to 'tell finder to mount' all the individual shares in the DFS and set it up that way.



May 17, 2019 3:11 AM in response to rccharles

Hi @rccharles,


I've created symlinks and that does the trick. However I ran into another issue: I linked all the shares in a subfolder-tree and my plan was to just set the folder permissions to 500 in order to block users from copying files to the ./Company folder instead of the actual shares. But instead of giving me permission denied errors, finder just asks for the user's password and copies anyway. It seems to automatically invoke sudo to overcome the permission error. Any idea on how to stop this?

May 17, 2019 10:33 AM in response to mdirickx

OK. That makes sense. You don’t want people doing anything intensive on the SMB shares anyway. Even Quicklook will lock it up eventually.


I suggest moving your visual tree out of /Volumes. Or at least, put it on a central, initial mount point on the server. You can create internal folders on it according to that structure. For the actual mount points, use Finder aliases. You will have to mount the desired locations once first. Then, drag the open server window from the icon in the Finder window title bar to the desktop while holding down option+command (I think). Then, anytime someone double-clicks on that alias file, it will mount that location.


You still won’t be able to control where in /Volumes things get mounted. But from a visual perspective, in the Finder, it will look the way you want.


There are two ways to specify point points. You can do it via autofs, but that requires the machine to be bound to the domain and the user in AD. It is really nice because you don’t have to hard-code passwords. But in the example you describe, that doesn’t sound like the right approach.


Another option would be to write a little program to mount these servers at the desired locations. AppleScript is pretty lame to begin with. There isn’t much you can do with it. Any other scripting language that will bridge to the underlying APIs will allow you to mount the servers in the desired locations.


However, you really shouldn’t mount things in /Volumes like that. Let the Finder own that. Don’t try to create your own folders. It might work and it might not. Just trying to mount SMB volumes puts you into unusual territory. When I see people having problems with mounts, it isn’t unusual to see them doing something funky like this in /Volumes. If you want a specific mount point, a lower risk option is a dedicated location elsewhere.

May 17, 2019 10:49 AM in response to mdirickx

the ./Company folder instead of the actual shares. But instead of giving me permission denied errors, finder just asks for the user's password and copies anyway.


I'm not a heavy on the ins and outs of sharing. Your in good hands with etresoft.


I'd look into how the server is configured. It seems to me the server should be able to block this. I've have heard some strange things about how base level Windows shares work. I'd look into ACL's.


R

May 17, 2019 2:02 PM in response to rccharles

Thanks @etresoft, that is quite clear. It is also more or less the approach I'm currently on. I've got a bash script that uses a tiny piece of appleScript to 'tell finder to mount the share'. That way I don't run into the username/password issues, or at least get a finder box that asks for credentials, and I'm not stuck in AppleScript all the time.


When a folder is mounted, the bash script checks where in /Volumes/ exactly the mount has been created and symlinks (alias might have been an alternative) it to a central directory in ~/Desktop/CompanyServers/.


This 'CompanyServers' folder on the user's desktop, is a tree of folders and symlinks. I know for sure that the less tech-savvy users will open this folder and assume that everything in there is on the server. To give a concrete example: say I have an external user coming in for a couple of days and he has a video that is meant for everybody. Our current folder sturcture is as follows:

~/Desktop/CompanyServers/Video/
~/Desktop/CompanyServers/Video/Public -> /Volumes/share1/subfolder2
~/Desktop/CompanyServers/Video/Internal -> /Volumes/share3/subfolder4

and this user decides ~/Desktop/CompanyServers/Video is the perfect spot to copy their folder Everybody.

When the user copies the files to the .../Video folder, the user will have the idea everything ended up on the server as it is filed under the .../CompanyServers folder. Though in reality, the folder Everybody was only copied to a subfolder the user's Desktop.


The issue I'm facing is: how do I protect these folders from writing? I appologize for this misunderstanding @rccharles, it seems I've been a bit too brief in my previous reply. It's not a server permission issue, it's a local issue. These folders are owned by the user. So I can easily do a chmod 500 to restrict write access. Unfortunately, whenever Finder runs into this, it simply asks for elevated privileges with a popup for the username and password and writes to it anyways. This even happens when I 'chown root:root' the folder. Is there any way to block writing to a folder on the Desktop?


Thanks

May 17, 2019 4:05 PM in response to rccharles

You could put a folder action on the folders you do not want them to add junk and ask them where to move the file to; should they not follow instructions. You can suggest the valid folders. for the move You could write apps for each of the folders and have them drop the files they want to save on the "correct" server and have the app copy the files to the server. This way the file will end up on the server or on the desktop. Of course if they want to look at the server ? double click is view or drop is copy. Of course, they could look around and see what is going on.


You want to assist the user from making an accidental mistake. You would need some other method for the malicious user.


No perfect world. I'd check out acl's and see if they have any more power.


R



May 17, 2019 4:37 PM in response to rccharles

Interesting. I don't get the 'but you won't be able to see them again' message. I have to confess that I'm testing on an older MacBook as it's company-owned and not joined to the domain. I'll give an update on Monday about that (haven't activated VNC yet).


I was looking into FolderActions as well. I nearly got a solution but got a few bugs in the bash script and paused my work there. I did manage to show a pop-up, coupled to each folder where I set the permissions to r(x)o.


Somehow I was hoping for a solution that actually blocks these actions. But if not, indeed FoldersActions will be my savior!


I'll update on monday

May 17, 2019 5:00 PM in response to mdirickx

How secure do those user credentials have to be?


You might try a more elaborate AppleScript that asks the user for their passwords and then uses “do shell script” to execute “mount” with the appropriate parameters to mount those volumes right where you want them.


Otherwise, I don’t see a real answer. If an elaborate solution isn’t really good and really stable, is really any better than a laminated sheet of instructions?

May 18, 2019 10:21 AM in response to mdirickx

fyi: folder actions example with debugging via on run.


(* 
  Demonstration of how dropping files on AppleScript icon works.  Shows how to debug via on run path. Shows items added to folder.
  
 Save as an Application Bundle.  Don't check anything.
 
 Shows log statement.
 
 It is easier to diagnose problems with debug information. I suggest adding log statements to your script to see what is going on.  Here is an example.
	
For testing, run in the Script Editor.
	1) Click on the Event Log tab to see the output from the log statement
	2) Click on Run


Author: rccharles

 *)


-- Gets invoked here when you run in AppleScript editor.

on run
	--  debug lines
	set desktopPath to (path to desktop) as string
	
	-- here is a log statment.
	log "desktopPath = " & desktopPath
	
	-- Be sure to select a file on your DESKTOP.
	set see to alias (desktopPath & "Picture 1.png")
	
	-- Simulate dropped items list.
	set dropped_items to {see}
	
	common(dropped_items)
	
end run


-- Folder actions.
-- Gets invoked here when something is dropped on the folder that this script is monitoring.
-- Right click on the folder to be monitored. services > Folder Action Settup...

on adding folder items to this_folder after receiving added_items
	
	common(added_items)
	
end adding folder items to



-- Gets invoked here when something is dropped on this AppleScript icon

on open dropped_items
	
	common(dropped_items)
	
end open



on common(dropped_items)
	
	-- Write a message into the event log.
	log "  --- Starting on " & ((current date) as string) & " --- "
	tell application "Script Editor"
		activate
	end tell
	
	
	log "class = " & class of dropped_items
	
	
	repeat with droppedItem in dropped_items
		log "The droppedItem is " & droppedItem & "; class = " & class of droppedItem
		
		display dialog "The droppedItem is " & droppedItem giving up after 3
	end repeat
	
	
end common




May 21, 2019 1:34 PM in response to rccharles

Haha! Good answer :)


It is indeed a feature. Quite an intuitive one that comes in very handy for most users.


As goes for any feature, it's only handy when you're doing what you're expected to be doing. A script timeout for example is a very common feature. It saves us from system crashes on a daily basis. Yet on the other hand, it also causes a lot of headaches for devs that need long-running jobs. Luckily, there usually is a way around a feature.


So here I am, wondering on how Finder implements this overlay of the mount directory with the mount target folder. I somehow think it's too inefficient to recalculate on folder viewing and too trivial to keep in memory, so my guess is it's stored somewhere on disk, though I have no idea on where to start looking. Any ideas?


Cheers!

May 21, 2019 4:34 PM in response to mdirickx

I think we should go back and revisit how you got to this situation.


Seems to me that your users will be familiar with how the mac does business. So, why all the duplication? Getting the shared folders on the desktop seems good enough for me. Users can access them in the standard way.


This seems to be the official way:

https://www.youtube.com/watch?v=4sdlfAvU5-M


I'll admit it's a little longwinded. The script could automate this process as much as possible.


R

Mount smb server 'tree'

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