New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Operating System General OS operation information and support

OS 10.5 - Login Script to Mount SMB Drive to Desktop


Post Reply New Thread Subscribe

 
Thread Tools
redbergy

 
Member Since: Nov 20, 2007
Posts: 6
redbergy is on a distinguished road

redbergy is offline
Hello Mac Experts! I just started drinking the Mac Kool-Aid when I ordered my first Mac - a MBP - last week. I must admit it tastes way better than the Windoze 3 day old cold coffee I'm used to. So far I'm loving it, but I'm running into one issue on my work network.

After trying for 3 hours with our Linux guru we could not get Finder to open a connection to our file/web server which is Debian (Linux) through Samba. I tried everything I could think of and there's not much help on Google.

Using the command line mount_smbfs I was finally able to mount the samba share on our Debian to a folder in my home directory. Right now this is fine, for the rest of the day I'll be able to work, but I'm just wondering if there is a way I can create a script that runs when I login that does the following:

1) At login check if my Server is available (192.168.1.216) (this in case I'm using my MBP on the road or from home)

2) Run this command if the server exists:
mount_smbfs //myusername:mypassword@192.168.1.216/share /pathto/mountfolder/ondesktop

3) The last part is the key (I guess) - I want this share to show up on my Desktop like when I connect a USB drive or how my Macintosh HD does

I'm assuming it's fairlly easy to create a script that runs at login? I've Googled a little with no success but I think the tricky part will making sure the 192.168.1.216 is a valid server -- or maybe there doesn't even need to be a check it just runs the command and if it's not there nothing happens? The other tricky part for me is figuring out where exactly I need to mount the drive to so that it appears on my desktop as a mounted drive instead of in my /Users/username/smbMount folder that I arbitrarily made.

The later is what I really need to konw as I'm sure with alot of Googling I can find the best way to create a login script in Leopard, but I have no idea where to mount it to and I'm afraid to just start trying to mount to some device in /dev/ which (I think) could potentially screw things up.

I'm looking for a step by step here if someone wouldn't mind helping out this Mac Newb.

Thanks in advance!!!
QUOTE Thanks
kirby14

 
kirby14's Avatar
 
Member Since: Nov 20, 2007
Posts: 93
kirby14 is on a distinguished road

kirby14 is offline
There is a write up somewhere (maybe on these forums) about using Automator to do this for you. It can definitely map the "drive" but I'm not sure if it will be able to check to see if the server is available first since I've never used it.

If I find the link, I'll post it here.
QUOTE Thanks
RiDE

 
RiDE's Avatar
 
Member Since: Sep 13, 2006
Location: Deep in the heart of Texas!
Posts: 3,559
RiDE has a reputation beyond reputeRiDE has a reputation beyond reputeRiDE has a reputation beyond reputeRiDE has a reputation beyond reputeRiDE has a reputation beyond reputeRiDE has a reputation beyond reputeRiDE has a reputation beyond reputeRiDE has a reputation beyond reputeRiDE has a reputation beyond reputeRiDE has a reputation beyond reputeRiDE has a reputation beyond repute
Mac Specs: Mac's

RiDE is offline
While the server is mounted...

Open System Preferences >> Accounts >>> login items.

Drag the Server icon and drop it in the Login Items.

This will mount the server at login.
QUOTE Thanks
redbergy

 
Member Since: Nov 20, 2007
Posts: 6
redbergy is on a distinguished road

redbergy is offline
Quote:
Originally Posted by RIDE View Post
While the server is mounted...

Open System Preferences >> Accounts >>> login items.

Drag the Server icon and drop it in the Login Items.

This will mount the server at login.
The problem is I can't access this share using the finder, for some reason Go > Connect To Server... will not allow me to connect to this Debian server using samba. The only way we've found is to Terminal in mount_smbfs - I'm asking if there is a way to do this during start up - I think I found out how by creating a .command file that runs in startup, but I still don't know how to do (1) check if server exists before creating a folder on my desktop and then mounting the file system to that folder.
QUOTE Thanks
redbergy

 
Member Since: Nov 20, 2007
Posts: 6
redbergy is on a distinguished road

redbergy is offline
I guess I should have been more clear in my post. For some reason, I cannot use Go > Connect to Server... in the Finder options. I get some type of error to the effect of "You do not have permission to access this drive" - when I type in an incorrect login I get a different error saying "Bad username or password". I can connect to this samba server using Windows and other Linux machines. I can also connect using smb in the command line of my Mac and I can mount the drive using mount_smbfs but for some reason I can't do the easy Finder way.

This is why I am asking about a start up script since it seems the only way I can access this share is by typing in the command line. I have a basic script going below, however I would like it to remove the two directories it creates first at startup, determine whether I can mount the share, then if I can, recreate those folders (that way if I'm not at work, I won't see the empty folders on my desktop)... Below is my script (.command file set to run at login):

mkdir /Users/adam/Desktop/blxshare
mkdir /Users/adam/Desktop/blxweb
mount_smbfs //username:password@192.168.1.216/blxshare /Users/adam/Desktop/blxshare
mount_smbfs //username:password@192.168.1.216/blxweb /Users/adam/Desktop/blxweb
KillAll Terminal
exit

So, like I said, first, I need to add a rm /Users/adam/Desktop/blxshare, then I need some way to check and see if 192.168.1.216 exists, if so, recreate the folder and mount the SMB share.
QUOTE Thanks
NanoBite

 
Member Since: Oct 27, 2005
Posts: 4,714
NanoBite is an unknown at this point

NanoBite is offline
redbergy, have you successfully mounted the share onto your Desktop so you have the share icon visible? Sorry if you've explained the contrary above.
QUOTE Thanks
redbergy

 
Member Since: Nov 20, 2007
Posts: 6
redbergy is on a distinguished road

redbergy is offline
Spawn - No problem, I'm not sure of the definition of "successfully". I am able to create a new folder on my desktop and then mount the SMB share to it successfully if that makes sense -- all using the command line.

mkdir /Users/adam/Desktop/blxshare
mount_smbfs //username:password@192.168.1.216/blxshare /Users/adam/Desktop/blxshare

I cannot get it to "mount" to the desktop using Finder.

So to reiterate - the OS doesn't make the share icon on the desktop for me, I have to manually create a new folder on the desktop and use a command to mount to that specific folder.
QUOTE Thanks
NanoBite

 
Member Since: Oct 27, 2005
Posts: 4,714
NanoBite is an unknown at this point

NanoBite is offline
This may be a bit left of centre to what you are trying to achieve but if you look at the image below:



When my share is mounted I dragged the icon to the menubar in a Finder window and when the share isn't mounted or if my PC is turned off, the icon reverts to a question mark.

When I know my PC is on and I want to mount the share I just click on the question mark and the share is automatically mounted:



I just thought that I should *share* this with you in case it is a workaround.
QUOTE Thanks
redbergy

 
Member Since: Nov 20, 2007
Posts: 6
redbergy is on a distinguished road

redbergy is offline
Okay here is my Startup script, currently it supports 2 shares (you can easily edit it to change it to more than 2 or only one) I hope this helps someone else.

Put this into a file with a .command extension and don't forget to hop in the terminal and type chmod +x myfile.command to make sure it has execute permissions. Drag the command file to your login startup applications and you should be good.
Code:
#!/bin/sh

# Put Samba Host IP as Host
host="192.168.1.xxx"

# Desktop Path with trailing slash
desktop="/Users/user/Desktop/"

# Share Username
username="yourusername"

# Share Password
password="yourpassword"

# Share 1 Name
shr1="share1"

# Share 2 Name
shr2="share2"

# Ping the host to see if it exists
outp=`ping -c 1 $host | grep "0% packet loss"`

# Based on ping create folders and mount 
# or don't mount and delete folders if they exist

if [ "$outp" = "1 packets transmitted, 1 packets received, 0% packet loss" ]; then
	echo "Found $host, mounting file systems..."

	# Share 1
	dir1=${desktop}${shr1}
	if [ ! -d "$dir1" ]; then
		# Can't Find Directory So Create It
		echo "Creating Mount Point: $dir1";
		mkdir "$dir1"
	else
		echo "Found Mount Point: $dir1"
	fi
	if [ -d "$dir1" ]; then
		echo "Mounting..."
		mount_smbfs //"$username":"$password"@"$host"/"$dir1" "$desktop""$shr1"
	fi

	# Share 2 
	dir2=${desktop}${shr2}
	if [ ! -d "$dir2" ]; then
		# Can't Find Directory So Create It
		echo "Creating Mount Point: $dir2";
		mkdir "$dir2"
	else
		echo "Found Mount Point: $dir2"
	fi
	if [ -d "$dir1" ]; then
		echo "Mounting..."
		mount_smbfs //"$username":"$password"@"$host"/"$dir2" "$desktop""$shr2"
	fi
	
else
	echo "Could not find $host..."

	dir1=${desktop}${shr1}
	if [ ! -d "$dir1" ]; then
		# Can't Find Directory So Do Nothing
		echo "No Unused Mount Point for $dir1"
	else
		echo "Found Unused Mount Point: $dir1"
		echo "Removing..."
		rmdir "$dir1"
	fi

	dir2=${desktop}${shr2}
	if [ ! -d "$dir2" ]; then
		# Can't Find Directory So Do Nothing
		echo "No Unused Mount Point for $dir2"
	else
		echo "Found Unused Mount Point: $dir2"
		echo "Removing..."
		rmdir "$dir2"
	fi
fi

# NOTE: If you have other Shell Scripts, or the Teriminal.app is running
#       enabling the next line will cause the entire Terminal.app to close.
#	If you are sure that you can kill the Terminal process feel free to 
#	uncomment the following line so that the Terminal window the script brings
#	up will automatically close when finished 

# KillAll Terminal
QUOTE Thanks
giulio

 
giulio's Avatar
 
Member Since: Mar 19, 2007
Location: NY USA
Posts: 1,813
giulio is just really nicegiulio is just really nicegiulio is just really nicegiulio is just really nice
Mac Specs: iMac 5.1 | iMac 7.1 | iPod Touch | iPod Nano

giulio is offline
Here is my solution, which uses automator:
  1. Launch Automator, which will create a new workflow.
  2. From the Finder Library, drag the Get Specified Servers Action into the workflow. Click the [+] and enter the address of your server. Something like cifs://server/share, then click Connect.
  3. From the Finder Library, drag the Connect to Servers Action into the workflow. Be sure 'Use Results from Previous Action' is enabled in the URLs pulldown. (The following three steps are optional. They will open a Finder window focused on the mounted share and set the View for it.)
  4. Add the Finder Action Get Specified Finder Items to the workflow. Click the [+] and select the share you want to automate mounting of. Click Open.
  5. Drag Finder's Open Finder Items Action into the workflow. 'Open with' should be 'Default Application.'
  6. To make sure the Finder honors your preferred view, drag Finder's Set Folder Views action into the workflow. Use the options to your liking.
  7. Select Save As, and set the File Format to Application. I suggest saving it to your user's Applications (~/your_user/Applications) folder, and naming it with the share's name.
  8. In the Finder, navigate to where you saved this Automator app. Drag the new app into your login items window.

It's never failed. And you don't have to worry about error checking anything like that. It's an app, so it runs in it's own environment, not dependant on terminal/etc.
QUOTE Thanks
JaRdaII

 
Member Since: Oct 26, 2008
Posts: 1
JaRdaII is on a distinguished road

JaRdaII is offline
hello, i was trying to use redbergy's skript, and it writes something like this:

<code>
Last login: Sun Oct 26 10:18:48 on ttys000
jarda-vitkus-macbook:~ jardavitku$ /Users/jardavitku/Desktop/mount.command ; exit;
Found 192.168.0.148, mounting file systems...
Found Mount Point: /Users/jardavitku/Desktop/iTunes
Mounting...
mount_smbfs: mount error: /Users/jardavitku/Desktop/iTunes: Unknown error: -1
Found Mount Point: /Users/jardavitku/Desktop/Data
Mounting...
mount_smbfs: mount error: /Users/jardavitku/Desktop/Data: Unknown error: -1
logout

[Process completed]
<code>

creates it two folders with correct names on the desktop, but they are empty.
Does anyone now where could be a problem? (finder connection works OK, but startup connection doesn't, it writes that host could not be found)

Question number 2): and if it will connect by a this skript, will it be the same asi finder connection? will i be able to eject it in findet?

3): how to asociate to that folder same picture as it is in finder-connected smbs ?

thanks for responds..
QUOTE Thanks
redbergy

 
Member Since: Nov 20, 2007
Posts: 6
redbergy is on a distinguished road

redbergy is offline
JaRdaII - Your problem seems to be in the mount_smbfs command:

Quote:
mount_smbfs: mount error: /Users/jardavitku/Desktop/iTunes: Unknown error: -1
It's possible that you'd have to play around with the mount_smbfs command in your Terminal to figure out how you can successfully mount your specific network shares. mount_smbfs has a lot of options - it could be possible that you need to specify something else to get your share working correctly. Once you get it working in the Terminal try changing the script to match your successful command.

If you don't plan on reusing the script, and don't care that it's modular you can simply change the lines under #Share1 and #Share2 that look like this:

Code:
mount_smbfs //"$username":"$password"@"$host"/"$dir1" "$desktop""$shr1"
mount_smbfs //"$username":"$password"@"$host"/"$dir2" "$desktop""$shr2"
to something like this:

Code:
mount_smbfs //user:password@ip/share /Users/username/Desktop/share
Obviously you'll hard code your username, password, ip, share's name (share), and the path to the folder on your local machine (the final argument).

We've since added a new file server and the OS now allows us to mount the drives using Finder - so I haven't looked at this script in a while.

Edit:

After looking over your output again it's possible that you could have your share name wrong (since that isn't ever in the output I'm just guessing) - but make sure that the host computer is configured for windows (samba) file sharing and does in fact have a shared folder with a name that matches your script. Again, this should be pretty easy to test out by opening Terminal and using the mount_smbfs command or checking on the host computer.

Hope that helps!
QUOTE Thanks
hagfish

 
Member Since: Jun 30, 2010
Posts: 3
hagfish is on a distinguished road

hagfish is offline
Quote:
Originally Posted by RiDE View Post
While the server is mounted...

Open System Preferences >> Accounts >>> login items.

Drag the Server icon and drop it in the Login Items.

This will mount the server at login.
Heh. Drag/drop! I would *never* have tried this, but I should have known.. Dragging "NormalFolder" from my "PLACES" menu didn't work. Dragging the share itself from the NAS in my "Shared" menu didn't work. But dragging NormalFolder from the share under "SHARED" worked fine, and is exactly the behaviour I was after. (Using 10.6).

SHARED > NAS (Windows BSOD icon) > Share (with 3 little people icon) > NormalFolder
QUOTE Thanks

Post Reply New Thread Subscribe


« bash 'export' command not working | 10.5.6 computer starts then shuts down »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
How to: Mount an external usb hard drive? stamko OS X - Operating System 8 09-28-2007 07:42 PM
Little disk drive looking things on desktop? brooklyn431 Switcher Hangout 9 07-05-2007 06:31 AM
Creating backups and bootable images... 2kx2 Switcher Hangout 4 05-26-2007 08:53 PM
Hard Drive Icon On Desktop KNEE Apple Notebooks 13 03-08-2007 10:17 AM
Upgrading hard drive...Boot IDE or SCSI? lokerd Apple Desktops 5 10-19-2003 07:02 PM

All times are GMT -4. The time now is 12:21 PM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?