






|
|
||
| Discussion Thread | http://forums.macosxhints.com/archive/index.php/t-16189.html |
The objective is to create scripts to mount network shares. I have the following:
mountK - mounts the C drive on my Windows computer as K: on Windows and /K on the Mac mountP - mounts the harddrive of my PowerBook as P: on Windows and /P on the Mac unmountK - unmounts K: on Windows and /K on the Mac unmountP - unmounts P: on Windows and /P on the MacIn fact, I have [un]mount{H|I|K|L|P|W} for 6 different resources I use all the time. And I have the scripts installed on 5 different machines (2 Macs and 3 Windows).
Just using the mount command simply doesn't cut it. Sure it creates a mount point - however the Finder doesn't know anything about it. We want the network share K to appear in the Finder and the directory /K to work from the terminal. Easy - here's how.
#!/bin/csh
if ( ! -e /K ) then
ln -s /Volumes/K /K
endif
ls /K/windows >& /dev/null
if ( $status ) then
echo "/K isn't mounted. Hang on."
osascript -e 'mount volume "smb://domain;username:password@machine-name/sharename"'
else
echo '/K is mounted'
endif
Now when we create the share (with the osascript command in a moment), the share actually appears on the Mac filesystem as /Volumes/sharename (in this case /Volumes/K). Not too helpful. So start by creating a symbolic link from /K -> /Volumes/K.
And now we tell the Finder to create the share with the osascript comment. This tells Finder to create the share. But first we check if it's not already mounted by looking at /K/windows. And if not, then we mount it.
There is however another complication. The sharename on Windows for the C: drive is usually "C". With Windows/XP-Pro (SP2), you can create a share with a name of your own choosing. Use K of course.
Use the following tip at your own risk: With XP/Home Edition, you don't appear to be able to assign your own name to a network share. It insists that the sharename of C: is C. I had to mess in the registry with the settings in HKLM/SYSTEM/CurrentControlSet/Services/lanmanserver/Shares. I renamed 'C' to be K and I renamed Security/C to be Security/K. And that did the trick and changed the share name to "K". The drive letter remains as "C:".
There is another way to mount the drive and get it to appear in the Finder. Use a command like this:
mkdir /Volumes/K sudo mount_smbfs "//domainname;username:password@machinename/share" /Volumes/K && disktool -rThis does the business. However, there are a couple of drawbacks. Firstly, you have to enter the password for sudo (for which I have a workaround, which I'll explain in a moment). Secondly, having been mounted this way, it appears to be impossible to unmount it again! I think it must be 'locked' into the OS by some daemon and the command '... umount /Volumes/K' delivers the message 'Resource Busy'. By the way, I have an alias in .cshrc which sets up:
setenv PASSWORD secretmagic alias ... 'echo $PASSWORD | sudo -S \!*'So, I can use ... command instead of sudo command and not have to enter the password. Of course the downside of this is that my password is in the .cshrc file. However, as I work at home on my own, there's nobody snooping around to discover the password!
The batch file mountK.bat on Windows is easy:
@echo off net use K: \\machinename\sharename password /USER:domain\username
No difficulty with this. However this does create a network connection. When you're on the host machine, you may prefer to use a subst instead. I suspect this is much more efficient, however I've never bothered to investigate this.
subst k: c:\
The script unmountK on the Mac is easy:
#!/bin/csh umount /Volumes/KWe don't need to tell the finder to do it. He sees the share disappear, and removes it from the desktop and the Finder UI. Getting status is easy. For example:
df /K df | grep VolumesThis reports the available space on all drives (and then filter to show only the shares in Volumes). You can use the script unmountAll:
#!/bin/csh umount /Volumes/?And finally the mountAll script to get all the network resources active at once.
#!/bin/csh mountH mountL mountK mountP mountW
The batch file unmountK.bat on Windows is easy:
net use K: /deleteOf course if you used subst to create K:, then umountK.bat is
subst K: /dI have a legal copy of the MKS toolkit installed on my Windows laptop. I like MKS a lot. This also saves a lot of 'mental gear crashing'. UNIX commands like df (disk free) work fine, detect and report the network shares. So it's obviously possible to enumerate the shares. However I don't know the DOS commands for this.
I haven't bothered to think about mountAll and unmountAll for Windows - I really haven't felt a need for this. They're probably trivial!
I'm very happy to accept comments, feedback and suggestions for any of my articles. I'm always happy to hear you - especially if you have constructive suggestions. And I'm particularily pleased if you can let me know about corrections.
|
Page design © 1996-2007 Robin Mills / webmaster@clanmills.com Updated Friday November 16, 2007 |
|