The Philosophy of the Script Sensei:
The command prompt is my best friend.
The FOR command is my second best friend.
The best scripts are written between 1AM and 3AM.
A Man who writes batch files will go hungry while the scriptwriter makes a good living.
A good script can do a thousand operations while the GUI does 25.
| The heavy door opened slowly and the blast of cold air cut right through me. The massive rack mounted Alpha servers whined in the background as the dedicated air conditioner pumped 65-degree air into the room. A lone occupant sat at the keyboard looking comfortable and in control of his vast Domain (NT Domain that is). "The command prompt is my friend", he said as he typed cryptic commands into the keyboard and smiled at the output that was being displayed on the monitor. "Did you know that if you use a FOR command to set an environment variable, you can use that variable in a called second sub-routine?" he queried. Perhaps I had stumbled into the UNIX computer lab by mistake. No, I could see the familiar NT wallpaper on the monitor screens around the room. I was in the right place and was about to meet the Script Sensei. "Would you like to help us add some users today?" he asked. "Sure," I said. A short time later the script I had copied and modified as per the Sensei's instructions began to run. | ![]() |
| I watched the lines flash by on the screen as a
100+ user accounts were created and put into their appropriate groups, I was hooked. This
was powerful addicting stuff. I could perform repetitive functions with more speed and
accuracy than was possible with the GUI. The Sensei looked pleased. He had another
convert. Each attempt I made at scripting was met with his familiar comment, "I'll
bet you could make this script even better with a few small changes." Each time I
returned with a small piece of the puzzle in place until one day I came in and he said,
"do you realize what this script can do?" He rattled off all the ways the script
was collecting, manipulating and presenting data. Completing only small sections at a time
I had lost count of the number of modules written and how the sum was now much greater
than its parts. Eating an elephant and writing scripts are the same in that they both must attacked one small bite at a time. The Script Grasshopper |
|
Adventures in Scripting-All of the scenarios that follow can be (and have been) solved with an NT command shell or Perl script. I write a monthly Real World Scripting Column for the Windows NT Magazine Win32 Scripting Journal. Many of my sample scripts are available through their web site at: http://www.ntserver.com/Newsletter/Scripting
You come into work on Monday and learn that the head of IS was
fired over the weekend because the main NT file server went offline. When the server came
back up all of its shares were gone. It took the rest of the weekend to reconstruct the
paths to the shares and get the complex permissions structure back in place. Your job is
to design a solution that will capture the share permissions, update any changes on a
daily basis and create a script that can be used to instantly recreate them if the weekend
disaster ever happens again.
The Windows NT and Win 95 user community at your site wants to have shortcuts placed on
their desktop to all the shares on the main servers on your network. These shortcuts are
constantly changing and you don't want to have to keep updating the shortcuts. The
supervisor of the help desk wants to have something her staff can send new users as an
e-mail attachment.
A domain migration occurs at your site. A short time after the migration is complete users
begin to complain that they occasionally find personal files on their workstations that
they can't open due to permissions problems. You have been asked to automate a remote
repair procedure for 1000 workstations.
You have a cluster server that occasionally fails over and you have been charged to
develop a way to handle share permissions when the cluster is in one of four states:
1. Normal condition.
2. All shares on node 1.
3. All shares on node 2.
4. Reversed condition with node 1 shares on node 2 and vice versa.
Your solution must be able to query the state of the cluster and apply the appropriate
permissions.
You are regularly doing desktop support and users get confused when they get ready to log
onto their machines and see a different username and domain in the Windows or Novell Logon
dialog box. How can you make it appear as though you were never logged onto their
workstations?
You are implementing a client backup solution at your company. You will be installing the
client software on 1000 workstations. On the workstation side there are several parameters
that must be entered that slow down the installation process. The backup solution also has
to be configured on the server side. The server side requires the NETBIOS name, IP
address, DNS name, backup group name, and schedule to be entered for each of the machines.
Is there any way that this server side configuration can be automated?
As a follow-up to the above scenario, the workstations above often move to different
locations in the company and their IP addresses are changed. Occasionally the desktop
support team reinstalls NT and overwrites the backup files on the workstation. Is there a
way to query these workstations and detect these changes since they will cause backup to
fail.
You have a Web server running with logging enabled. The company president asks you to
produce a report that will show the Web traffic. You go to your log file directory and to
your horror discover that the server has been logging daily. You are now confronted with
merging 31 log files that are extremely large. Every time you try to open one of the log
files in Notepad or WordPad to cut and paste the application crashes. To make things worse
the Web team director asks you to filter out transactions on 6 specific pages because they
are banners in frame set pages that he is afraid will distort the statistics.
You are asked to develop a solution for clearing a directory of document files every 7
days. The Technical Writers at the company use this as a drop location and they are
supposed to delete their own work but keep forgetting and the folder soon fills with old
projects. The required result is that the director wants all the files that are in the
folder on Monday get deleted the next Monday. If the file is added to the folder during
the week it does not get deleted until the Monday the next deletion cycle.
Your boss wants you to develop a web based report. He wants this all placed in a table
format with the disk space free shown for each of the drives on the main file servers. He
wants this produced dynamically every morning so he can come in and review the statistics
on the corporate Intranet.
Your boss has asked you to write a script that will send a popup message to the
appropriate administrators when any of the critical servers go offline. In addition he
wants the script to time and date stamp the failure event in a log file. The last IS
director bought a program that pings the servers occasionally but you have since learned
that sometimes your servers have answered pings successfully even when they are offline.
One of your web servers has the WWW service stop running occasionally. You have been asked
to write a script that will determine the state of the service and restart it if
necessary.
The disk drives on the file server are constantly filling up and you suspect that there
are a considerable number of duplicate files in the directory structure. You have been
asked to write a script that will capture all the files over 10MB for each of the 15
engineering groups and write them to 15 .HTML formatted files that will be placed on the
company Intranet.
You have noticed that there has been a reduction in throughput between some servers in your server farm. Some file copy operations are very quick while others are very slow. You have been asked to write a script that will test actual file copy throughput for determining Disk I/O problems, bad NICs, bad cables or a misconfigured network switch.
The file and folder structure on the main file server have been getting very deep and some users have complained that they have had problems accessing files they have saved. You suspect that the path length to some of these has grown to over the 255 characters that NT and Win95 support. There are over 250,000 files you need to check for path length and also print an exception report.