As system administrators begin their careers, most start to control their networks the hard way—manually. At first, this can be a fun and rewarding learning process, but the novelty soon wears off, and tasks become tedious and labor-intensive. My mentor was quick at the draw, always teaching me to automate as much as I possibly could, since it makes life easier down the road and also saves huge amounts of time. The more time you save your company, the more productive you can be.
In a previous TechTip, I explained how to use the utility Autoruns to administer Windows services when you're not using an Active Directory environment. This month, I'll show you how to spawn remote processes when you're running a Linux back-end but you have to manage Windows machines on the desktops without Active Directory to control items remotely. This proves useful for many situations.
BeyondExec
The utility BeyondExec, written by Craig Peacock, is the perfect tool for spawning processes remotely on Windows desktops when no Active Directory environment is at your disposal.
My use of this tool began some time ago, when I needed to schedule a shutdown job of my Windows machines on a nightly basis. The Windows built-in shutdown.exe program would have suited my needs, but actually scheduling the jobs on each box was just more work than I wanted to tackle. I sought a way to script this process so that one machine could spawn all others to execute the shutdown procedure. A Google search revealed this tool, and for more than a year now, I've been using BeyondExec to safely reboot the machines every night.
Command Line Usage
Start by downloading the zipped file from the link above, unzip it to a place of your choosing, and fire up a windows command line to see the usage of the tool. (My preference is to create a folder "beyondexec" in a convenient place in the C drive and then unzip the file into this folder.) When you're done, you should have a path to the .exe file similar to C:eyondexeceyondexecv2.exe, from where you can launch the program to view the usage.
The program operates by copying a service file, rexesvr.exe, to the remote machine to register as a service, then executing whatever set of commands you pass along for it to process, and finally returning back with either a success or failure message.
A simple example of rebooting a machine remotely via the command line looks like this:
You must enter a proper user name and password. If an administrative account isn't used with the same privileges on the remote machine, then a dialog box appears asking for credentials. I suggest creating a domain administrator account on your network, using that account, and then changing the password frequently. The only complaint I have with this utility is that it doesn't offer any form of encryption for the password. It is intended to run on a secure network, however, so problems should be minimal. If you're logged into the machine with a domain admin account, then no passwords should need to be passed along; it should authenticate as the account you are logged on the machine with. In addition, the password isn't stored on any machines unless you script it; then, it will be stored on a single machine.
As mentioned, this is a simple shutdown command to execute. There are many more arguments that can be passed along, such as displaying messages to the users, forcing applications to terminate, and ignoring computers in use. For some reason, users get a bit testy if their machines suddenly reboot when they're in the middle of a project. Read the full documentation at the Web site or the usage at the command line for detailed information about the various options.
Scripting This Utility
Now that you've learned a few basic command line operations for this utility, let's move along to automating processes.
Recently, a few users raised some complaints about their PCs being very sluggish. As I investigated the problem, I realized that the machines hadn't been defragmented in quite a long time. Having a file system that is almost 60% fragmented usually is a good indicator, so I set out the following weekend to remedy the problem.
I started to write a simple script to remotely start the defrag process. After a bit of experimenting to make sure it actually functioned (because, according to Microsoft, defrag.exe can't be launched remotely), I was able to get my test victim to cooperate. Then, I scheduled machines to start doing so once a month. Let's see how this is accomplished:
First, create a simple Windows NT Command Script file with your favorite text editor, and then save the file with the .cmd file extension. You must do this so Windows knows how to handle the file.
I won't go into a lot of detail about the actual scripting variables, but a sample of my defrag script, titled defrag_script1.cmd, looks like this:
set directory=C:eyondexec
set command=beyondexecV2.exe
set args=-u username -p password -w C:WINDOWSsystem32defrag.exe C:
%directory%%command% machine1 %args%
%directory%%command% machine2 %args%
%directory%%command% machine3 %args% ...and so on.
Save this file and then you can schedule just one Windows machine to start the process instead of having to manually defrag machines on your network. Then, you can use the task manager to schedule the .cmd files to run when specified.
BeyondExec has a group switch where you can read a list of machines in from a text file instead of doing the above, but for my situation, I've had better results executing each command separately. This gives the process a chance to execute and return back before moving on to the next. You should experiment to find the best solution for your situation.
Script Away...
As demonstrated, it's fairly easy to write a few simple scripts to make your life of administration at the desktop level a little easier. I've shown you one example where the defrag process can be automated, and I've shown you the example of a great remote restarting tool, but this utility does far more than what is listed here. Other features include mapping network drives, distributing registry keys, copying files, applying software patches...almost anything you set out to accomplish remotely.
BeyondExec has saved me countless hours of work and is worth looking at if you're running Linux servers with no Active Directory tools installed. Now, go write a few scripts and spawn away!
Max Hetrick is a PC Support Analyst/Specialist who holds a certification as a MCSA. He also has experience with installation and maintenance of Linux operating systems from the PC to server levels. Max can be reached at
LATEST COMMENTS
MC Press Online