The Waitfor Command
The resource kit’s Waitfor utility is interesting because to use it, you need two machines (typically, a server and a client) in the same domain. The best way to describe how this utility works is with an example. Begin by running the code that Listing 1 shows on the client. On the client’s screen, notice that only the first line of code runs and displays the message Here is the first line of code. Then, on the server, run the command
Waitfor –s freds-signal
This command sends a signal that triggers the client into completing the tasks you programmed in with the code in Listing 1. The –s switch specifies the signal (in this case, freds-signal) that the client waits for. When the client receives this signal, it runs the rest of the lines in Listing 1, one line at a time, until it receives another Waitfor signal. This example involves only one computer receiving the signal. Multiple machines can wait for the same signal.
The Waitfor command has a –t switch that lets the client code time-out if the client doesn’t receive the specified signal. If you don’t use the –t switch, the default wait time is forever. As Listing 2 shows, you simply add to the client code the –t switch followed by the number of seconds you want the client to wait. On the server, you run the same Waitfor command you ran previously.
The Start Command
If you have a task in which you need to start several scripts either sequentially or at the same time, you can use the Start command. The Start command launches a separate command shell window to run a specified command or script.
For example, suppose you need to simultaneously launch the four scripts that Listing 3,4,5 and 6 show. Listing 7 contains a master launching script that you can use. By using the Start command, you can launch all four scripts virtually simultaneously.
Listing 8 contains a variation of the launching script. In this script, I added the /wait switch to the Start command. This switch prompts the Start command to wait for each script to finish running before launching the next command shell window.
Hooked on Scripting
This lesson completes my 10-lesson introduction to Windows shell scripting. I hope you’ve enjoyed the lessons and become hooked on scripting.
Homework Assignment
- Find out what the scripts in Listings 3 through 6 are doing. Run the command
Color /?
in a command shell window.
- The Start command offers many parameters and switches. Explore your options by running the command
Start /?
in a command shell window.
forrukh October 27, 2003