Understand the role of scripting in network administration

Administrators are typically burdened with tons of tasks, many of which are repetitive. One of the best ways to automate such tasks is to use scripting. Here's a look at how scripting can help streamline your work.

Network administrators have used scripting since long before Windows or even DOS came on the scene. UNIX administrators, for instance, have been using shell scripting and its powerful capabilities for decades. Scripting can significantly ease the burden of network administration. But learning to create useful and effective scripts for networking tasks is not easy and requires a lot of patience and practice. Before you begin, it’s important to have a good understanding of what scripting is and why it is so useful.

In this first article of my series on scripting, I will provide information to help you understand how scripting can play a role in network maintenance and management. In subsequent articles, I will talk about the various scripting languages and platforms, basic programming concepts for scripting, and using Windows shell scripting and Visual Basic scripting for network administration. I'll also point you toward other resources that are available for learning how to write scripts.

What is scripting?
Simply stated, a script is a small, interpreted program that can carry out a series of tasks and make decisions based on specific conditions it finds. By “interpreted,” we mean that when it is run, it is carried out one line at a time, as opposed to “compiled,” which is the process of turning it into machine language before it is run. A script is created using ASCII text, so Windows Notepad or a similar text editor is the only tool required.

A number of scripting “languages” are available for you to choose from, each with its own capabilities and limitations. These languages include Windows native shell scripting, Visual Basic Scripting Edition, JavaScript, Kixtart, and Perl. Which one you choose will ultimately depend on a combination of the tasks required and your own experience and inclinations.

Each scripting language has a collection of commands or keywords and a set of rules on how to use them. The set of rules for writing a script in any given language is called the syntax. Once you learn the keywords and syntax, you can use a text editor to write the script and then save it with a file extension that is appropriate to the scripting language you are using. Some of the more common file extensions you will see are .bat, .cmd, .vbs, .js, and .kix.

How is scripting used?
Scripting lets you automate various network administration tasks, such as those that are performed every day or even several times a day. For example, login scripts run every time a user logs in to the network and can perform tasks like mapping network drives for the user based on certain conditions, such as group membership. Another example of script use might be a situation where you want to have each Windows NT server create a new Emergency Restore Disk and then copy the contents of that disk to a network location.

Other tasks might need to be carried out only once, such as a modification to the registry, but to a large number of servers that are widely distributed geographically. In a case like that, you could create and distribute a single script to run the task on each server.

You can start scripts manually, but you can also start them automatically, either by a specific event or scheduled via the Windows Task Scheduler. Windows NT allows scripts to be run automatically each time a user logs in to the network. Windows 2000 goes much further and can be configured to automatically run separate scripts upon:
  • Machine startup
  • Machine shutdown
  • User login
  • User logout

You could, for instance, map specific network drives when a user logs in and then automatically copy that user’s Favorites folder to a network share when he or she logs out so that the data is preserved in a central location.

The scripting advantage
Scripting in network administration offers significant advantages. It allows you to:
  • Save time—Scripts can carry out complex tasks and be invoked automatically, without the intervention of the network administrator, so the admin can concentrate on other tasks while the script runs.
  • Be consistent—A script need be written only once and can then be invoked many times. It is much less error-prone than manually carrying out the task each time.
  • Be flexible—Scripts can use decision-making logic to respond to different conditions. Rather than statically mapping a workstation to persistent drives, for example, network drives can be mapped in a variety of ways based on which user is logging on to the machine. You could write a script to check whether a file exists and delete it if it does or display an error message if it doesn't. The only real limit to scripting is your imagination.

As you can see, learning to create scripts for automating network administration is well worth the effort, even if it does require some work. In my next article, I will discuss the various choices you have in scripting languages and platforms.

Editor's Picks

Free Newsletters, In your Inbox