Skip to main content
Question

Script to mount SMB share?

  • August 12, 2010
  • 31 replies
  • 96 views

Forum|alt.badge.img+12

Does anyone have an easy script to auto mount an SMB share that I could make a policy with through casper? I have a bunch of Windows servers used for online testing in our school district that have a data folder that needs to mount for the client program to work. Any help would be appreciated.

Thanks
-Josh

31 replies

stevewood
Forum|alt.badge.img+38
  • Hall of Fame
  • August 12, 2010

This should work, but it will pass the password in clear text and it will be
On Thu, Aug 12, 2010 at 1:03 PM, <josh.glassing at spps.org> wrote:
stored in the script. You could write this in AppleScript and use some
dialogs to grab the user name and password:

#!/bin/sh

userName="user"
userPass="pass"
shareName="server.mynetwork.com/sharename"
whereToMount="/Volumes/Share"

mount_smbfs //$userName:$userPass@$shareName $whereToMount

Now, I have not tested that script, but I did test the mount_smbfs from the
Terminal to make sure it worked. Of course, this will not mount the volume
on the desktop. Not sure how to do that.

Steve Wood
Director of IT
swood at integer.com

The Integer Group | 1999 Bryan St. | Ste. 1700 | Dallas, TX 75201
T 214.758.6813 | F 214.758.6901 | C 940.312.2475


Forum|alt.badge.img+21
  • Contributor
  • August 12, 2010

stevewood
Forum|alt.badge.img+38
  • Hall of Fame
  • August 12, 2010

Also, the whereToMount location needs to exist before running the
mount_smbfs command. So you may want a command in there that does:

mkdir $whereToMount

before the mount_smbfs command.

Steve


Forum|alt.badge.img+31
  • Honored Contributor
  • August 12, 2010

Do you use Kerberos?

tell application Finder

mount smb://server.com/sharepoint

end tell

If everything is kerberized you shouldn't need to authenticate.


  • August 12, 2010

This is one that I use. Ultra basic.

-- Grant Lutz


Forum|alt.badge.img+12
  • Author
  • Contributor
  • August 12, 2010

Cool I really appreciate all the replies from everyone, I am going to try some of these out.

-Josh

Re: [Casper] Script to mount SMB share?

Grant Lutz (CW) to:
josh.glassing at spps.org, casper at list.jamfsoftware.com
08/12/2010 01:40 PM

This is one that I use. Ultra basic.

-- Grant Lutz


John_Wetter
Forum|alt.badge.img+33
  • Hall of Fame
  • August 12, 2010

NWEA Testing? If so, there are all kinds of fun automation scripts floating around this list and the MN-EDU list. Just want to confirm before we narrow into that.

-John


Forum|alt.badge.img+7

What Craig said.
There's a network mount script in the resource kit you should examine.

-Lance


Forum|alt.badge.img+12
  • Author
  • Contributor
  • August 12, 2010

Yes sir NWEA testing!

fun stuff!

-Josh

Re: [Casper] Script to mount SMB share?

John Wetter to:
Casper List
08/12/2010 03:17 PM


Forum|alt.badge.img+31
  • Honored Contributor
  • August 12, 2010

If it is NWEA testing....I feel your pain. I have an article how I deployed it and dealt with it over the pat 3 years.

http://tlarkin.com/tech/how-deploy-nwea-testtaker-64-intel-macs-casper

Not fun


  • August 12, 2010

The mount_smbfs // line is actually sufficient by itself, so long as it has
the user name & password ­ no real need for variables unless you're pulling
that info from elsewhere.

Good idea to create the mount point directory as well.

Mounting the shares on the desktop is easily enabled in the Finder
preferences ­ on the General tab under 'Show these items on the desktop:'
--> Connected servers. :)


Forum|alt.badge.img+7
  • Contributor
  • August 13, 2010

We started using the one in the resource kit over the weekend, and it works flawlessly for us. By the way, if you don’t specify the server and mount point, it will default to the user’s SMBHome. That’s not in the documentation, but it’s in the code comments. I wasted about 8 hours trying to figure out how to do exactly that (ours still aren’t mounting automatically) before I figured that out. Then I felt really dumb :-)


Forum|alt.badge.img+17
  • Honored Contributor
  • August 13, 2010

The one in the resource kit works well for us too.

Anyone know if it's possible to set the share to mount hidden (if you have network shares set to show in Finder). I believe we used to do this through WGM with login items for mounted servers.

Thanks!


Forum|alt.badge.img+21
  • Contributor
  • August 13, 2010

I will be deploying it everywhere here at UWEC as I roll out Snow Leopard
here the next few weeks.

It was a lot more reliable on 10.6 than 10.5. The only other thing I did was
create a script for logout that forces the unmount of these shares as well.
If you have a fast login turn around, the system sometimes doesn't quite let
go of those mounts/folders in time for the next person when they login.
Nothing shows up because the command will say the share is already there,
but still has permissions for the previous user.

Also, if you login with a local login that's not domain and can't use those
shares they hang around for a long while, too...at least it appeared to be
that way.

#!/bin/sh

. /etc/rc.common

/sbin/umount -f /Volumes/<share>

Craig E


Forum|alt.badge.img+12
  • Author
  • Contributor
  • August 13, 2010

I think I'm just having problems with the syntax in the resource kit, I am pretty much a scripting noob, I don't know if I am inputting the values correctly in the hardcoded value sets. If anyone is willing to share theirs filled out that would be very helpful.

Thanks a bunch for everyones help and input
-Josh

Re: [Casper] Script to mount SMB share?

casperadmin to:
'Buckner, Mark', Lance Ogletree , Casper List
08/13/2010 06:43 AM


Forum|alt.badge.img+17
  • Honored Contributor
  • August 13, 2010

It's important that Kerberos is working for this to work - to make sure go, connect to server, type server name, are you prompted with share names without authenticating? If so Kerberos is ok, and you should be able to use resource kit script.

The only values I changed were

afp (I wanted afp, you can use smb)
Server
Sharename

So our server is serversharename<file:///serversharename> and this is what my script looks like

# HARDCODED VALUES SET HERE
loginUsername="$3"
shareUsername="$3" #The username of the user to be used to mount the share
authType="kerberos" #Valid values are "kerberos" (default) or "password"
password="" #Note this only needs to be set if authentication type is "password"
mountType="afp" #The type of file share. Valid types are "afp" (default) or "smb"
serverAddress="server" #The IP address or DNS name of the server - if left blank, the script will search for the "SMBHome" attribute in the user record
share="sharename" #The name of the share you are mounting - if left blank, the script will search for the "SMBHome" attribute in the user record


Forum|alt.badge.img+21
  • Contributor
  • August 13, 2010

I didn’t change anything in the script. I added the script to the JSS and then I use policy to customize the options I want, so I can reuse the script for multiple shares with multiple policies.

And what has been mentioned is correct. Kerberos must be working properly for this to function, and the east test is to try and mount the SMB share logged in as that user and not get prompted for authentication.

See attached screens.

Craig E


Forum|alt.badge.img+31
  • Honored Contributor
  • August 13, 2010

Error on line 1? What shebang are you using? #!/bin/sh?


Forum|alt.badge.img+12
  • Author
  • Contributor
  • August 13, 2010

The beginning of the script has #!/bin/sh

I had been opening it in textedit. I removed the script from casper admin, deleted the resource kit off my computer and re downloaded it and uploaded the default mount script from the resource kit straight to admin without opening/modifying it and I am still getting the error.

Re: [Casper] Script to mount SMB share?

Thomas Larkin to:
casper-bounces, josh.glassing, Craig S. Ernst
08/13/2010 08:59 AM

Cc:
"Lance Ogletree", "Casper List"

Error on line 1? What shebang are you using? #!/bin/sh?


Forum|alt.badge.img+31
  • Honored Contributor
  • August 13, 2010

Copy/paste it in something like TextWrangler and have it show
"invisible" which will show you all tabs and spaces. Perhaps you got a
weird white space in there or something which happens sometimes when you
copy/paste stuff for coding.


Forum|alt.badge.img+12
  • Author
  • Contributor
  • August 13, 2010

It doesn't look like there are any out of place spaces or tabs in it in invisible mode. I'm using the original mountNetworkShare.sh that comes in the resource kit with no modifications, only thing i'm doing is labeling the parameters after it goes into casper admin... hmmm :-

Re: [Casper] Script to mount SMB share?

Thomas Larkin to:
josh.glassing
08/13/2010 09:13 AM

Cc:
"Lance Ogletree", "Casper List", casper-bounces, "Craig S. Ernst"

Copy/paste it in something like TextWrangler and have it show "invisible" which will show you all tabs and spaces. Perhaps you got a weird white space in there or something which happens sometimes when you copy/paste stuff for coding.


Forum|alt.badge.img+31
  • Honored Contributor
  • August 13, 2010

OK

I just looked at the script in the resource kit. Are you running this script as a log in policy? It looks like it is using $3 to find the currently logged in user, which I believe only parses properly when logging in. Casper must run the script, and it must be at log in for $3 to return the proper user name.


Forum|alt.badge.img+12
  • Author
  • Contributor
  • August 13, 2010

I just made a policy to run the script and tried it on a couple different computers with different user names (all of which have access to the share and connect up just fine if i command+k connect to them) and the policy status is kicking back the same error as casper remote was... I really hope I'm not overlooking something obvious :-

Re: [Casper] Script to mount SMB share?

Thomas Larkin to:
josh.glassing
08/13/2010 09:50 AM

Cc:
"Lance Ogletree", "Casper List", casper-bounces, "Craig S. Ernst"

OK

I just looked at the script in the resource kit. Are you running this script as a log in policy? It looks like it is using $3 to find the currently logged in user, which I believe only parses properly when logging in. Casper must run the script, and it must be at log in for $3 to return the proper user name.


Forum|alt.badge.img+31
  • Honored Contributor
  • August 13, 2010

The only thing I can think of, is that you aren't inputting the proper ServerAddress or share and it is defaulting to the SMB home when trying to mount?


Forum|alt.badge.img+12
  • Author
  • Contributor
  • August 13, 2010

Here is where I start to get a little confused, does the "share" refer to where it's mounted on the machine receiving it or refer to the share on the server itself. For example server.stuff.org/test

would I just put "test" in the share section or the entire path... or is it reference to the client machine and I need to have an already existing directory with which to mount it to?

Thanks again for all your patience and continued responses a million posts later

Re: [Casper] Script to mount SMB share?

Thomas Larkin to:
josh.glassing
08/13/2010 10:09 AM

Cc:
"Lance Ogletree", "Casper List", casper-bounces, "Craig S. Ernst"

The only thing I can think of, is that you aren't inputting the proper ServerAddress or share and it is defaulting to the SMB home when trying to mount?