Unix Tip: Use your Unix scripting skills to write a batch file

July 18, 2007, 08:35 PM —  ITworld.com — 

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.


> NET USE
Status Local Remote Network

-------------------------------------------------------------------------------
OK L: \\central\Library Microsoft Windows Network
Unavailable M: \\bigserver\shs Microsoft Windows Network
Disconnected P: \\bug-tracker\projects Microsoft Windows Network
OK R: \\smokey\reports Microsoft Windows Network

Sign up for ITworld's Daily newsletter
Follow ITworld on Twitter @IT_world

I like it!
Close

On Twitter now

Unix

Powered by Twitter
You are logged in | Sign out
Sign in and post to Twitter

What are you thinking?

Cancel Tweet sent

On Twitter now

Post a comment
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
peer-to-peer

Esther Schindler
If the comments are ugly, the code is ugly

claird
SVG a graphics format for 21st century

pasmith
Take Chrome OS for a test spin

Sandra Henry-Stocker
Solaris Tip: Have Your Files Changed Since Installation?

sjvn
64-bits of protection?

jfruh
Android fragments vs. the iPhone monolith

mikelgan
What Gizmodo missed about the Pro WX Wireless USB disk drive

 

Where Google Chrome security fails: the password
I heard mention that the Chrome OS will have some sort of encryption available a la bitlocker. If it's possible to encrypt personal data using another password or key, then it may have potential for very secure data.... And Ubuntu has an 'encrypt home directory' option, perhaps google should follow suit.
- Dann

Join the conversation here

The Daily Tip

The Daily TipQuick, practical advice for IT pros. Made fresh daily.

Hot tips:

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.

Newsletters

Subscribe to ITWORLD TODAY and receive the latest IT news and analysis.

I would like to receive offers via email from ITworld partners.
By clicking submit you agree to the terms and conditions outlined in ITworld's privacy policy.
Featured Sponsor

AISO founders envisioned a Web hosting company that was environmentally friendly. While the company employed energy-efficient innovations like solar panels, its infrastructure produced unacceptable power and cooling requirements. Find out how AISO leveraged AMD technology to overcome their challenge in this case study white paper.

In this whitepaper, Scalar explores the opportunity to change the landscape with respect to mission critical databases built around Oracle. Leveraging technologies such as Linux, high-end commodity processing power and Oracle RAC technology to architect, design, build and maintain database infrastructure that delivers maximum availability, reliability and performance at a fraction of traditional cost.

On a typical day, weather.com, the Web site for The Weather Channel in Atlanta, serves up between 15 million and 20 million page views. But in September 2004, when back-to-back hurricanes ransacked Florida, the peak traffic on one day more than tripled: over 70 million page views by more than 7 million unique visitors. Read the full success story now.

Marketplace