Skip navigation

Mounting a file share via script and Fast User Switching

1267 Views 10 Replies Latest reply: Nov 19, 2012 1:03 PM by evantklooster RSS
Björn Herrmann Level 4 Level 4 (2,450 points)
Currently Being Moderated
Oct 11, 2012 7:37 AM

Hi everyone,


sometimes I need to mount a file share using a shell script. It is usually something like this:


mkdir /Volumes/data

mount -t smbfs //username@ /Volumes/data


This works fine as long as there’s only one user account on the Mac. The problem is that sometimes there are 2 or more users sharing a Mac. They often use Fast User Switching since they do not want to log out in between. User A issues the shell script to mount the share. User B logs in via FUS and wants to access the share, too. But he/she instead gets an error from the script:


mkdir: File exists


Of course that is correct since /Volumes/data would only get removed if user A logs out or unmounts the volume. Any idea how to make this a bit more intelligent/reliable?




  • evantklooster Calculating status...

    hey! This seems like a perfect solution to the fast user switching in combination with afp mounts.


    Can you elloborate a little more on how to implement this?


    Right now I have 2 users on my mac and have an automator script that mounts the afp shares. But then I have the problems descibed with data and data-1


    do I need to apply the script above everytime when loggin in? How?



  • evantklooster Level 1 Level 1 (0 points)

    awesome explanation! thanks for this excellent information.


    I have been playing around with network accounts and managed to get it to work with my diskstation. But then.. if I'm outside the home, I cannot login with the network user accounts. So I guess I'll stick with the normal accounts.


    I can just use the one user I have on my diskstation (admin:password) and hardcode it into the script right? I the script is loaded on different accounts on the Mac, they will mount with this credentials in the home directory.


    one lost question: the mkdir... that should be only needed once I guess? Not everytime the user logs in?


    thanks again!

  • evantklooster Level 1 Level 1 (0 points)

    awesome! I managed to make an application with the automator with the script in it.. and it works! I have been searching for this on the net for ages.. never thought the solution would be so simple Finally no Documents-1 anymore !


    anyways: left with a few things.. somehow I can't manage to add the share in my sidebar favourites of the finder.. you know a way to fix that?


    and.. not quite able to completely test it: but how will this work with awake from sleep mode?


    thanks again, really appreciate you're helping me out.

  • evantklooster Level 1 Level 1 (0 points)

    Hi Bjorn,


    I've been playing around with the shares, but it is not yet working as I wanted. I'm not able to add them to the sidebar... and them stay there. If I fast user switch back and forth.. then I see that under my 'mac book air' (available in the sidebar) there a 2 versions of all my shares. One has a mounted sign.. and one has a no access sign. I guess this is because the mount also exists for the other user. I think this is messing up the favourite links in the sidebar.


    Also.. when I check my server under 'shared' I notice that it is not connected by default. It always connects just when I click the server..



  • evantklooster Level 1 Level 1 (0 points)

    Hey Bjorn,


    Have tried opening a MS word-document with above solution. I thought I finally had it, but now it seems.. I cannot open documents. Get an error saying the file is in use.




More Like This

  • Retrieving data ...

Bookmarked By (0)


  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.