Unix Tip: Use your Unix scripting skills to write a batch file
Attaching a remote drive or directory on a Windows box is called "drive mapping" though the process is essentially the same as what we call mounting in the Unix world. While I rarely spend any significant time working on the Windows end of a Samba connection, I recently had an opportunity to assist a user who was tired of repeatedly having to manually connect directories from a couple of Solaris servers equipped with samba for sharing directories with select Windows desktops.
The solution was to whip up a batch file that mapped the drives on login. Batch files, though far less sophisticated than their Unix shell script counterparts, nonetheless have many of the important features that I have become accustomed to working with on my Unix systems. These include such things as redirection, testable return codes, the ability to test for the existence of a file and the equivalent of /dev/null for discarding command output, errors and all.
Batch files can include comments (lines that stat with "REM" for remark or the less distracting "::"). They provide a looping mechanism that uses the syntax "FOR %%VAR IN (LIST) DO". They provide a command (CHOICE) that works like a case statement. There is even a FIND command that works like grep. While the language still seems primitive in comparison to bash and perl, I was surprised that I was easily able to write a script that did what I needed it to do and automate the process. Admittedly, it was splattered with GOTOs -- something that would have horrified my CS professors from decades ago. Still, it was a functional language and I was pleased that I managed to mimic what I would have done on a Solaris or Linux system on a Windows XP box.
The command that is used to map drives on a Windows box is called "NET USE". While there is a GUI process for mapping drives, I prefer to open a DOS command window to view and modify my drive mappings to any point and click operation.
NET USE without arguments prints a list of the drives that are mapped along with any that were previously mapped and since disconnected. The command is similar to the Unix mount command.
|
Sign up for ITworld's Daily newsletter
Follow ITworld on Twitter @IT_world
On Twitter now
Unix
Powered by Twitter
jfruh
Apple syncing patent can't come soon enough
pasmith
New Twitter features borrow from 3rd party clients
Esther Schindler
Open Source Changes the Software Acquisition Process
mikelgan
How to set up continuous podcast play on the new iTunes
David Strom
Five important Windows 7 mobility features
sjvn
Guard your Wi-Fi for your own sake
Sandra Henry-Stocker
Grepping on Whole Words
Sidekick: The Good News & the Bad News
Either way you look at it Microsoft Data Center management did not follow standards or best practices in this failure. In which case it makes me wonder more about the outsourcing of corporate data much less personal data.
- mburton325
Join the conversation here
Quick, practical advice for IT pros. Made fresh daily.
Want to cash in on your IT savvy? Send your tip to tips@itworld.com. If we post it, we'll send you a $25 Amazon e-gift card.













