Skip navigation

The Command Shell and Simple Database Structures

A Request from Reader Murat Yildirimoglu

Murat Yildirimoglu recently wrote me with his thoughts about the Command Shell. He'd like Microsoft to read and respond. 

Murat's Thoughts 
Mark Minasi once joked: "What do you use to administer a remote UNIX server? Telnet. What do you use to administer a remote NT server? A plane ticket."

This joke pointed out the weakness of the Windows command shell. Microsoft learned its lesson and made many efforts. PowerShell is the latest effort. I’ve long believed the command shell to be very strong indeed, even before PowerShell. For example, you can use the Net view command to list the computers in your domain or workgroup. After you get the list, you can use the TASKLIST /S machinename command to look at the processes running on a specific computer. Then you can use the TSKILL processname /SERVER:machinename to kill a specific process. And if you want to stop a service on that machine you can use SC \\machinename STOP servicename. And these are just some examples.

What I need most in the command shell are some simple database structures. Microsoft uses lightweight versions of SQL Server in many products. For example, in ISA 2006, the logs are stored in a SQL database. Likewise, I want a SQL Server database with predefined System Tables that can be installed and used in the command shell.

I foresee the use of only two system tables with predefined columns. Let's call the first one System Table1 and the second one System Table2.

These system tables can be managed by a programming language similar to xBase languages. xBase languages were simple to program, yet they were so powerful. They could manipulate and query tables easily.

When I issue the Net View command, the list is displayed on the screen. With system tables, the list would be imported to the System Table1 also. The result of the Net View command is the names of the computers. So, only one column of System Table1 would be used, and this column would have the names of the computers.

After getting the list to the System Table1, I want to stop a process in each computer. So I should use a loop construct like Do while not.eof()in xBase languages. The script would be like the following:

 

Select 1 (Use System Table1)

Net View  (This command populates the first column of System Table1)

Go top (Go to the first record, that is, first row in the table)

Do while .not.eof() (loop until the end of the table)

   TSKILL processname /SERVER:column1

   skip

enddo

 

That's all. With only 7 lines of code, we can stop a specified process in every computer.

Let's imagine a different task: Find out the process in every computer, that is using the most memory. For this task, we’ll use two commands: Net view for the list of the commands and TASKLIST to find all the processes on a computer. And we need two system tables for this task: One for the names of the computers, one for the information about the processes on a computer. The script would be like the following:

 

Select 1 (Use System Table1)

Net View  (This command populates the first column of System Table1)

Go top (Go to the first record, that is, first row in the table)

Do while .not.eof() (Loop until the end of System Table1)

   Select 2 (Use System Table2)

   TASKLIST /S systemtable1-column1 (Gets the computer name from the first column of System Table1 and lists the tasks on that computer)

   * After this command, the columns of System Table2 are populated with the result of the TASKLIST command. The fifth column would have the memory amount.

    Sort columnfive (This command sorts the rows according to the memory usage)

    print columnfive (Prints the name of the process that consumes memory most)

   zip (erases all the information in the System Table2)

   Select 1

   skip

enddo

 This script uses only 12 lines of code and finds out the memory-hungry processes on the computers. These scripts are also pedagogical. I'm a trainer and I can use these tables to teach the fundamentals of database structures. I hope Microsoft will do something like that.

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish