Shelling Out An NT Toolkit

Just recently I was building some shelves at the boat storage unit. While unloading thewood, a saw and some nails, I noticed the only other tool I had was a screwdriver.Afterseveral hours of trying to drive nails with a screwdriver, I realized it would've beenfaster and easier to go get a hammer.

Quite often the choice of the right tool is not clear-cut and can be subject toopinion. A good example is performing system administration tasks. I like the Korn shell,while many people prefer the C or TC shell.

I'm sure that if you look hard enough, you'll find someone who prefers the Microsoftcommand tools (command.com, cmd32.com and cmd.com).

Yech! I hate using those tools for system administration tasks on Windows NT. Mostlyit's because I don't know their secrets.

A WINDOW ON THE PAST

I find NT's basic DOS command set to be very primitive. Add in the fact that my fingerswant to type slashes to separate directory names instead of backslashes and you can seewhy I strongly prefer UNIX commands issued from the Korn shell for administering NT.

A Korn shell on NT? Absolutely! I expect that some of you are puzzled, while others areknowingly nodding their heads. In our NT Administration for UNIX Admins class, people areoften amused when I demonstrate NT commands from a Korn shell. What surprises me, is thatso many people have never heard of the product I use.

This column will introduce the MKS Toolkit to those unfamiliar with it. I was firstintroduced to this tool several years ago by one of our instructors using it on Windows3.1. The purpose of the MKS Toolkit is to provide the majority of UNIX commands, and the Cand Korn shells, on Win32 Operating Systems (Windows 95/98/NT). It also runs on OS/2 andDOS, but because I don't know much about them, you're on your own there.

Mortice Kern Systems Inc. (Waterloo, Ontario) develops and markets it as a developmentand productivity tool for PCs. While that may be true, for me it's survival software forPCs. When I need to perform complicated tasks, the only effective way for a UNIX geek likeme is by issuing commands. For example, if I want to rename a complete directory of files,I'm much more comfortable with a for loop, mv and sed commands than with a batch file. MKStoolkit lets me perform that task exactly as I would on a UNIX workstation.

A SHIELDED ENVIRONMENT

Installing the toolkit is done using either the autorun process on the CD-ROM, or byinvoking the install.bat command file. Once that's done, you'll see the usual setup shieldprogram. Behind the scenes, installation has set some environment variables, such as PATH,HOME, SHELL and ROOTDIR in your autoexec.bat, as well as made some registry settings forfiletypes.

The software gets loaded into a specified target directory, which is assigned as thevalue to the ROOTDIR variable. It will have two subdirectories. The etc directory containsconfiguration files and commands, libraries and some documentation pages (in the cat7subdirectory). The mksnt directory contains all the UNIX commands, which of course are inthe form of .exe files.

GETTING TO THE ROOT

For example, $ROOTDIR/ mksnt/ls.exe is the toolkit version of ls, which works almostexactly like the UNIX ls command. Remember that the PATH variable should be set correctlyso you don't need the entire pathname, but like most UNIX geeks, I think it's nice to knowwhere things are installed. Some other utilities are also in the mksnt directory, forexample Perl 5.004. This means you have to be careful to execute the correct perl.exe ifyou have another Perl installed elsewhere on the machine.

If you let the installation do so there will be an application group created somewherein the startup menu for the MKS Toolkit. Many tools can be started from there, such as theKorn and C shells. Once you start one of these, most of the normal UNIX things happen.

For example, there are shrc and login files, both in the etc directory and possibly inyour home directory. If they exist, they are run. The windows come up rather small, butcan be changed with font settings from menus in the window. Once this window is up, you'reessentially running a UNIX shell on a Win32 operating system!

Prove it by trying the ls command, or maybe ls -l /. Life is good! If you're in the Cshell, set the history variable and you can start using all the usual history invokecommands. Same for the Korn shell: Almost all its functionality is there, such as filenamecompletion, command recall and echo mode.

I started this column with an example of renaming a bunch of files. If the MKS ToolkitKorn shell is running, the following will rename all files in the current directory thatend in .htm to end with .html:

for file in *.htm
  do mv $file ${file}l
done

 

You'll find that most of the usual UNIX processes work, for example, sed, awk, vi, andfind. Release 6.2 is the first in which the find command works properly and, if you're aUNIX developer having to develop code on PCs, make is also part of the toolkit. If youload MKS Toolkit on an NT server, then load a telnet daemon, you can login over thenetwork, get a UNIX shell and actually get some remote work done.

PEEVED, NOT PERFECT

All is not perfect, however, and there are some negative issues and I have some petpeeves. First the peeves. It seems to me that each release moves slightly farther awayfrom true UNIX customs. Maybe the developers are spending more time on PCs and forgettingUNIX.

For example, the default prompt for the C shell is #. As any UNIX user knows, it shouldbe %. The # prompt is reserved for the root user. They also made the default prompt forthe Korn shell to be the current directory, without the $ symbol, which signifies that youare in a Bourne shell derivative (which the Korn shell is).

They also have an example in the shipped profile file that you can uncomment which willmake the prompt a % in the Korn shell! Gack! If the prompt is %, I'll start using C shellhistory invoke, since that's what % means.

Don't get me wrong, I still love the tools, it's the culture that's getting confused.You can use the startup files to perform any customizations you want, thus setting thingsstraight.

Maybe the biggest issue to be wary of is the use of pathnames. The toolkit allows youto use cd /fred/planes instead of cd\fred\planes which is typical on a PC. This is reallynice. I like using UNIX pathnames. The problem arises if you're executing administrativeWindows commands from the toolkit shells.

For example, if I issue the net use command, it works fine, displaying all the sharesI'm using. But if I want to issue the command to mount a remote drive, I have a problem.Here's the NT syntax: net use <drive>: \\UNC\share. For example net use e:\\reneespc\cd will redirect drive e: to the share named cd located on reneespc.

SLASHING THE NET

The problem is that the Windows command net expects pathnames with backslashes, but theKorn shell uses slashes in pathnames and has other meanings for backslashes, so we mustescape them. The command above would error on syntax, but net use e: \\\\reneespc\\cdwould work.

As long as we're using the MKS utilities, we don't have to worry about this. It's onlywhen you start mixing up Windows commands and UNIX shells.

A couple of tips to remember to get started: You must exit the shells. Don't try toclose the shells with the close window symbol. The key sequence <alt><enter>toggles from windowed mode to full screen. You can hit the full screen symbol by mistakeand have a hard time getting back into a window if you forget this.

Having the vi editor on a PC makes it worth the price of the toolkit. In fact, the lastfew releases of the toolkit have both vi (in a shell) and viw (in a separate window). Viwhas several useful menu tools and looks like a cross between xemacs and vi.

VI FOR ATTENTION

All vi commands work, but you can also save, close and open with menu buttons, as wellas cut, copy and paste. Several other tools have been enhanced to run both in command lineand Windows mode, such as du, ps, crontab, grep, diff and tar (visual pax).

If you must work on a Windows machine, but hate struggling with the mouse, try the MKSToolkit. It's like moving to Windows without really being there.

-- Fred was last seen paddling his boat with a tablespoon.

Must Read Articles