The ability to sort and extract (i.e., process) information from a list is a handy scripting technique. By sorting and extracting information from a list, you can reduce the number of input and temporary files that a script must use to complete its tasks, thereby reducing the script's complexity and execution time. This month, I want to show you some advanced For command techniques for sorting through a list and picking out specific lines of information.
ServerStatus.bat, which you can find in the Code Library on the Windows Scripting Solutions Web site (http://www.winscriptingsolutions.com), began life as a quick solution to server-uptime problems at a client site. Originally, the script used three input files to test servers for Ping response, services, and share availability. The script then used seven temporary files, which it created and deleted as it ran, to sort the test data and organize it into a report. I quickly realized that the script was too complicated for easily testing the existence of a new share or pinging a server. Consequently, I undertook the job of combining the three input files into one file and eliminating all the temporary files.
Getting Started
The single input file that ServerStatus.bat uses contains three types of test inputinput for the ping test, input for the service test, and input for the share test. For the ping-test input, you create entries that specify the servers you want to ping. For each server, you provide the server name and IP address, such as
work1,192.168.1.100
For the service-test input, you create entries that specify the services you want to test. The Netsvc utility, which you can obtain from the Microsoft Windows 2000 Server Resource Kit or the Microsoft Windows NT Server 4.0 Resource Kit, will use this input to perform service-status tests. For each service, you provide the name of the server on which the service runs, followed by the service's friendly name (i.e., the name that appears in displays) and the actual service name (i.e., the name the OS uses internally). For example, a service-input entry might look like
dom1pdc,RPC Locator Service,RPCLOCATOR
For the share-test input, you create entries that specify the shares you want to test. For each share, you provide the name of the server on which the share exists, followed by the share's friendly name and the actual share path. Here's a sample share-input entry:
dom1pdc,Test2 Share,
\\dom1pdc\test2
You combine all the entries into a comma-separated value (CSV) file named ServerStatusInput.csv. The contents of this input file should resemble the contents that Figure 1 shows. You might notice that the sample ServerStatusInput.csv file doesn't follow a strict order according to server or type of test input. You would probably see this type of variance in the real world as different administrators add test targets over time. In a production setting of 50 servers, for example, the number of individual items you're checking for can easily grow beyond 200, and items can be added out of order. Fortunately, you don't need to group the entries by server or type of test input in ServerStatusInput.csv. A For command in ServerStatus.bat sorts the entries.
Prev. page  
[1]
2
next page