Subscribe to Windows IT Pro
September 25, 2001 12:00 AM

Shell Scripting 101, Lesson 10

Windows IT Pro
InstantDoc ID #22582
Rating: (2)
Downloads
22582.zip

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

  1. Find out what the scripts in Listings 3 through 6 are doing. Run the command
  2. Color /?

    in a command shell window.

  3. The Start command offers many parameters and switches. Explore your options by running the command
  4. Start /?

    in a command shell window.

Related Content:

ARTICLE TOOLS

Comments
  • Anonymous User
    7 years ago
    Feb 24, 2005

    All the 10 lessons are really helpful for beginners like me. Thank you so much. Krishnamoorthi.BM.

  • forrukh
    9 years ago
    Oct 27, 2003

    I want to poweroff my PC running on Linux platform automatically after a certain period of time from logon using shell script. What will be the code?

You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.