Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


September 25, 2001

Shell Scripting 101, Lesson 10

RSS
Subscribe to Windows IT Pro | See More Batch Files Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

Download the Code Here

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.

End of Article

   Previous  1  [2]  Next  


Reader Comments
<P>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?</P>

forrukh October 27, 2003


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

Anonymous User February 24, 2005


You must be a registered user or online subscriber to comment on this article. Please log on before posting a comment. Are you a new visitor? Register now




Top Viewed ArticlesView all articles
WinInfo Short Takes: Week of November 9, 2009

An often irreverent look at some of the week's other news, including some more Windows 7 sales momentum, some Sophos stupidity, Microsoft's cloud computing self-loathing, more whining from the browser makers, Zoho's "Fake Office," and much, much more ...

Command Prompt Tricks

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

Windows 7 Sets Sales Record

Microsoft CEO Steve Ballmer described Windows 7's first ten days of sales as "fantastic" while in Japan yesterday. ...


Related Articles Shell Scripting 101, Lesson 9

Shell Scripting 101, Lesson 8

Shell Scripting 101, Lesson 7

Shell Scripting 101, Lesson 6

Scripting Whitepapers From Development to Production: Streamlining SharePoint Deployment with DocAve Deployment Manager

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 Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format


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 DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement