Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  Advanced Search 


March 20, 2000

Getting Started in NT Shell Scripting, Part 2


RSS
View this exclusive article with VIP access -- click here to join |
See More Windows NT Shell Scripting Articles Here | Reprints | Or sign up for our VIP Monthly Pass!

Last month, I showed you how to go from having an idea for a script to determining that script's requirements and writing the pseudocode. This month, I show you how to transform the pseudocode into a script and how to test this script.

You'll be creating the script ShareCapture.bat, which periodically captures share settings. Its output creates another script, RecreateShare.bat, which rebuilds shares if they disappear. Listing 1, page 2, contains a step-by-step explanation of what is occurring in ShareCapture.bat. You can download ShareCapture.bat from the Code Library on the Win32 Scripting Journal Web site at http://www.win32scripting.com. The downloadable version doesn't include the step-by-step explanation because this information would interfere with the script's execution. The Code Library also includes an example of RecreateShare.bat.

Transforming Pseudocode Tasks 1 and 2
After you write the pseudocode, you need to transform it into Windows NT shell scripting code. First, you need to write the code that captures the share information (i.e., pseudocode task 1). To accomplish pseudocode task 1, you use the basic Rmtshare command

Rmtshare \\work1

Next, you need to filter that command's output to remove the lines you don't want (i.e., pseudocode task 2). You must eliminate several lines, so let's begin by removing the lines that contain the administrative shares and the line that says the command completed successfully. To remove these lines, you use the Findstr command with two switches: . . .

Reader Comments
<p>I have just found this Web site - excellent.
A brilliant article, if only I could get it to work and I know it will. I couldn't get the piping of the rmtshare cmd to work. When I type the command with the /v, it just says <i>The command failed: 123.</i> If I leave the /v out, it just returns to a C:\> prompt with no command output.<br>
<br>
Piping works with all other commands apart from rmtshare it seems. I downloaded the rmtshare.exe and copied it my resource kit folder. I also tried it in the system32 folder on my Win2K server machine. I also tried this piping command on my Win2k prof machine same problem. Any ideas would be greatly appreciated.</p>

Stuart June 10, 2002


<p>I couldn't get rmtshare to work with piping. The cmd line that didn't work:<br><br>
rmtshare \\servername | findstr /i /v "string"<br><br>

It took me 2 hours to figure out that I needed an extra backslash after the server name. The following cmd line works:<br><br>
rmtshare \\servername\ | findstr /i /v "string"</p>


Stuart June 10, 2002


You must log on before posting a comment.

If you don't have a username & password, please register now.




Top Viewed ArticlesView all articles
The Memory-Optimization Hoax

Don't believe the hype. At best, RAM optimizers have no effect. At worst, they seriously degrade performance. ...

Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

SET Options and Recompilation

Learn how to tweak your server's SET options so that you don't have to constantly recompile. ...


Related Events Check out our list of Free Email Newsletters!

Scripting eBooks Keeping Your Business Safe from Attack: Encryption and Certificate Services

Best Practices for Managing Linux and UNIX Servers

Building an Effective Reporting System

Related Scripting Resources Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro Windows Dev Pro IT Job Hound ITTV
IT Library Technology Resource Directory Connected Home Windows Excavator Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing