UNIX-Like Add-ons

UNIX is a great server operating system (okay, I'm a bit biased here!), but it's not a very good desktop operating system. It certainly doesn't make sense for a laptop or palm-based device (in my opinion). Instead, if you're like the vast majority of us computer users, you've opted to use Windows or a Macintosh system. The good news: With the tools discussed in this final lesson, you'll find that you can have the best of both worlds: UNIX functionality within your existing desktop environment!

Task 24.1: Learn About the MKS Toolkit

Recognizing early on that a UNIX-like work environment would be a great addition to the graphical interface of Microsoft Windows, Mortice Kern Systems of Ontario Canada has been offering its UNIX toolkit since 1985. Over those years, not only has Windows changed quite a bit, but its toolkit has changed too. Indeed, I remember when it was a package of about 20 basic UNIX commands.


Today, the MKS Toolkit has more than 230 UNIX commands available as a valuable addition to your Windows environment, including vi, make, the Korn shell (a super Bourne shell), sed, the grep family of commands, find, Perl, awk, and much more.

What's particularly nice is that there are some easy icons you can click to get right into the MKS environment, letting you easily flip back and forth between a sophisticated UNIX-like command shell and the friendly Windows interface.

The MKS package has some quirks, however, the strangest of which to me is the promotion of the oddball lc command over the more flexible (and standard) ls command for listing files and directories. Fortunately, both are included with the system.

Learn more about the MKS Toolkit at the Web site http://www.mks.com/.


  1. As you can see in Figure 24.1, the MKS Toolkit offers various program icons, the most useful of which is the Korn Shell application, which launches a terminal window running the Korn shell, a very UNIX-like environment.

    Figure 24.1. The MKS interface to Windows.

    Once started, the new window offers a very DOS-like prompt,

    [C:/]
    

    which is actually an MKS prompt. Let's start by moving into a different directory, the actual folder where all the files that are on your Windows desktop are saved:

    [C:/] cd /windows/desktop
    

    Notice in particular that you don't have to worry about uppercase directory names and that, unlike in DOS, you can use / between directories, rather than .

  2. The regular DOS commands are available, including DIR:

    [C:/WINDOWS/Desktop] dir
    Volume in drive C is WINDOWS_95
    Volume Serial Number is 3719-12E1
    Directory of C: WINDOWS Desktop
    
    .              <DIR>        08-01-96 11:28a .
    ..             <DIR>        08-01-96 11:28a ..
    CDROM          <DIR>        11-05-97  7:38p CDROM
    IMPORT~1 TXT           131  02-18-98  9:06p import-me.txt
    DAT-9712       <DIR>        03-09-98  9:38a DAT-9712
    CCWP-B~1       <DIR>        09-24-97 10:06a CCWP - bad files
    DAT-9712 ZIP       426,461  03-09-98  9:38a dat-9712.zip
    CCWPSC~1       <DIR>        11-05-97  7:05p CCWP Screen Shots
    WIN95          <DIR>        12-16-97 11:38a Win95
             2 file(s)        426,592 bytes
             7 dir(s)     189,923,328 bytes free
    

    But the whole point of the MKS Toolkit is that there are UNIX alternatives. Let's try ls:

    [C:/WINDOWS/Desktop] ls
    CCWP - bad files   CDROM              Win95              import- me.txt
    CCWP Screen Shots  DAT-9712           dat-9712.zip
    

    A nicer format, very UNIX-like, but with less information than the DIR command. With ls it's easy; add a flag:

    [C:/WINDOWS/Desktop] ls -l
    total 834
    drwxrwxrwx   1 0        0              0 Sep 24  1997 CCWP - badfiles
    drwxrwxrwx   1 0        0              0 Nov  5  1997 CCWP Screen Shots
    drwxrwxrwx   1 0        0              0 Nov  5  1997 CDROM
    drwxrwxrwx   1 0        0              0 Mar  9  1998 DAT-9712
    drwxrwxrwx   1 0        0              0 Dec 16  1997 Win95
    -rwxrwxrwa   1 0        0         426461 Mar  9  1998 dat-9712.zip
    -rwxrwxrwa   1 0        0            131 Feb 18  1998 import-me.txt
    
  3. Alternatives to DIR don't make for a very compelling toolkit, so let's look at another alternative command: find, a sophisticated tool that lets you search for particular file names or types across an entire disk.

    In this case, I'm going to search for all files on the C: disk that have the suffix .sys and have the word command within the matching file or directory:

    [C:/] find / -name "*.sys" -print | grep -i command
    /WINDOWS/COMMAND/DRVSPACE.SYS
    /WINDOWS/COMMAND/ANSI.SYS
    /WINDOWS/COMMAND/COUNTRY.SYS
    /WINDOWS/COMMAND/DISPLAY.SYS
    /WINDOWS/COMMAND/KEYBOARD.SYS
    /WINDOWS/COMMAND/KEYBRD2.SYS
    /WINDOWS/COMMAND/DBLSPACE.SYS
    

    You can see that pipes are well-supported within the Windows environment. The file command offers some insight into the file DISPLAY.SYS, matched in the preceding output:

    [C:/] file /windows/command/display.sys
    /windows/command/display.sys:   maybe DOS device driver (.SYS)
    
  4. You can also create aliases for command sequences you like, exactly as you saw in the C shell:

    [C:/] alias dir="ls -CF"
    [C:/] cd /home
    							

    Now when you use the dir command, the results are somewhat different from those at the beginning of this lesson:

    [C:/HOME] dir
    ADV-HTML.DOC*       IMALL.doc*         TechSpecs/         imall- head.gif*
    Advanced HTML.ppt*  SH_HISTO*          Unix Secrets/      intro to html/
    

If you're looking for the power and capabilities of UNIX without leaving Windows, simultaneously running your favorite graphical application, then MKS can be an excellent choice. With the inclusion of Perl, make, and many other commands, it's a powerful and flexible environment.


MKS Toolkit includes some other very cool commands too, special additions that let your shell scripts act like Windows applications. I'll give you a peek in the next section.

Task 24.2: Turn a UNIX Shell Script into a Windows Application

Re-creating the majority of UNIX commands within a Windows-compatible DOS window would be valuable—indeed, that's what the original MKS Toolkit was all about. But the folks at Mortice Kern Systems added several new commands that let you pop up dialog boxes, file open boxes, and more, all from right on the command line or within a shell script.


The key commands are msgbox, which pops up a dialog box requesting input; filebox, which displays either an open file or a save file dialog box; start to produce a new window; and dlg to produce generic Windows dialog boxes.

A quick example will show you how these can help create powerful new commands for your Windows environment.

  1. The new command is called browseX and it's a simple tool, letting you browse through the files on your system, choose one to edit (with vi), and then launch a new window for editing if the file is in fact editable. If file indicates that the file isn't of type ASCII or shell commands, an error dialog box is displayed.

    The first step is to prompt for a file. This is done using the filebox command:

    filename=$(filebox -ant "Browsex: Select a file to edit")
    

    The -a flags ensures that the file exists, the -n flag prevents the Network button from being displayed, and the -t followed by "Browsex: Select a file to edit" is the title of the file dialog box.

    Figure 24.2 shows the resultant display.

    Figure 24.2. Choose a file from the filebox dialog box.

  2. The filename variable is set to the file the user specified, but what if the user chooses Cancel? Then the variable has no value. This can be tested like this:

    if test ! "$filename" ; then
      exit
    fi
    

    If the user clicks Cancel, the program exits.

  3. Otherwise, it's time to find out what the file command has to say about the file the user specified:

    desc=$(file $filename | cut -f 2-)
    

    Just like regular UNIX, MKS offers the useful cut command, which lets us chop out the first word of the file output (which is the filename being checked).

    Testing the results can be done with the test command, just like in UNIX again:

    if [ "$desc" = "ASCII text" -o "$desc" = "shell commands text" ]
    then
      # regular ascii text or shell commands text
      msgbox -fqb yesno -d1 -i information "BrowseX: Edit a file" "Would you
      like to edit $filename?"
      case $? in
        $Yes)  start -xt "Editing file $filename" viw $filename ;;
         $No)  exit ;;
      esac
    else
      # sorry, it's not an editable file...
      msgbox -fqb ok -i hand "BrowseX: Can't edit that file" "$filename is $desc"
    fi
    

    The first conditional can be read as “if the file type is ASCII text or if the file type is 'shell commands text' then…”

  4. If the file can be edited, the msgbox command is used to give the user a chance to edit the file, as shown in Figure 24.3.

    Figure 24.3. Would you like to edit that file?

    If the user chooses to make changes, the start command is used to invoke the windows-friendly version of vi (viw), which is shown in Figure 24.4. Here's the line that makes this happen:

    $Yes)  start -xt "Editing file $filename" viw $filename ;;
    

    Figure 24.4. It's vi with a friendly face.

  5. Finally, if the file isn't editable, the msgbox command is again used, this time to output a meaningful error message. An example is shown in Figure 24.5.

Figure 24.5. Can't edit a Zip archive!


To get a copy of the entire browsex.ksh script, jump over to http://www.intuitive.com/tyu24/.


If you've been looking for an easy way to slap a graphical interface onto existing shell scripts for a Windows environment, this aspect of the MKS Toolkit can prove to be a tremendous boon. It could be more flexible, but for quick improvements it's hard to beat. Even better, it's 100% portable to the Windows NT environment too.


Task 24.3: Learn About MachTen

The MKS Toolkit is a good extension to the standard commands for the Windows environment, but UNIX is more than just some commands available in a shell. The MKS Toolkit works with the Windows operating system, but if you're living in a Macintosh world like I usually am, a Windows product doesn't help.


That's where the slick MachTen product from Tenon Intersystems offers a way cool alternative for us Mac folk. Instead of just being a command shell, it's actually a complete UNIX implementation, including its own multitasking capability; a complete X Window System implementation (which can run in parallel to the Macintosh desktop); and a complete development kit for C, C++, Objective-C, Ada, and Fortran.

Even more helpful, the entire set of online man pages is included, so you have a complete UNIX implementation running in parallel to your favorite Mac applications.

Visit Tenon Intersystems online at http://www.tenon.com/.


  1. Starting MachTen looks like booting a regular UNIX system, with file-system checks and more. Finally, after a few minutes of starting, you're presented with a login prompt. I logged in and immediately had a terminal window I could use to explore the MachTen environment. You can see what that looked like in Figure 24.6.

    Figure 24.6. Working with MachTen is just like real UNIX!

  2. Large networked UNIX systems often connect to remote file systems with the Network File System, or NFS. With NFS file systems available, users can use // as a shorthand to jump to a virtual directory that shows all the systems available on the network. Borrowing a page from that, MachTen uses // to let you jump to the “top” of the actual Macintosh file system (by default, the / works with the virtual file system):

    taylor 21 : cd //
    taylor 22 : ls -CF
    %a5temp%a5/             Girl Ipo/               Personal/
    AppleShare PDS*         Icon%0d*                Shutdown Check*
    Applications/           Internet Mall/          System Folder/
    Book Projects/          Linda's Stuff/          Talks/
    Business/               Norton FS Comment*      Temporary Items/
    Desktop DB*             Norton FS Data*         Trash/
    Desktop DF*             Norton FS Index*        VM Storage*
    Desktop Folder/         Norton FS Volume*       Writing/
    DesktopPrinters DB*     Norton FS Volume 2*
    Games/                  OpenFolderListDF%0d*
    

    The %a5 is a Mac “bullet” icon (•), but this listing is exactly what's available on the hard disk.

  3. It's easy to use the find command to see whether the Elm Mail System is included with the MachTen package:

    taylor 29 : find / -name elm -print
    find: /home/ftp/etc: Permission denied
    find: /home/ftp/usr: Permission denied
    find: /home/ftp/bin: Permission denied
    find: /var/cron: Permission denied
    find: /var/spool/mailbox: Permission denied
    find: /var/spool/post.office: Permission denied
    find: /Network Trash Folder/Trash Can #2: Permission denied
    

    Nope, I just got a bunch of error messages because I'm trying to use the find command as a regular user, and clearly some areas are off limits.

    Instead, let's see what other matches I can find by searching for anything that has the word mail in it. To avoid tons of output, I'll skip any matches with the word emacs, man, or X11 (the X Window System files):

    taylor 33: find / -name "*mail*" -print |& egrep -v '(emacs|X11|man)'
    /etc/sendmail.cw
    /etc/mail.rc
    /etc/sendmail.cf
    /usr/share/misc/mail.help
    /usr/share/misc/mail.tildehelp
    /usr/share/misc/sendmail.hf
    /usr/share/skel/dot.mailrc
    /usr/share/nvi/tcl_scripts/mailprocs.tcl
    /usr/bin/mailq
    /usr/bin/mail
    /usr/bin/formail
    /usr/bin/mailstat
    /usr/bin/procmail
    /usr/sbin/sendmail
    /usr/sbin/mailstats
    /usr/libexec/mail.local
    /home/root/.mailrc
    /home/mtuser/.mailrc
    /home/mtnext/.mailrc
    /home/taylor/.mailrc
    /var/log/maillog
    /var/log/sendmail.st
    /var/mail
    /var/mail/maildrop
    /var/spool/mail
    /var/spool/mailbox
    /bin/rmail
    
  4. Even better, MachTen is a complete network-friendly implementation too, so copying files to or from another system on the Internet is easy.

    First, I need to move a file from the Mac desktop into my MachTen home directory (remember, the // notation is what's needed):

    taylor 41 : cp //Desktop  Folder/browsex.ksh $HOME
    taylor 42 : cd $HOME
    taylor 43 : ls -F
    bin/            browsex.ksh*
    taylor 44 :
    

    The file has been copied into my home directory, and now it's time to copy it onto my remote Web server with ftp:

    taylor 44 : ftp intuitive.com
    Connected to intuitive.com.
    220 limbo.hostname.com FTP server (Version wu-2.4.2-academ[BETA- 15](1)Sat Nov 1 03:08:32 EST 1997) ready.
    Name (intuitive.com:taylor): taylor
    331 Password required for taylor.
    Password:
    230 User taylor logged in.
    Remote system type is UNIX.
    Using binary mode to transfer files.
    ftp> put browsex.ksh
    local: browsex.ksh remote: browsex.ksh
    200 PORT command successful.
    150 Opening BINARY mode data connection for browsex.ksh.
    226 Transfer complete.
    1958 bytes sent in 0.017 seconds (1.1e+02 Kbytes/s)
    ftp> dir
    200 PORT command successful.
    150 Opening ASCII mode data connection for /bin/ls.
    total 2952
    -rw-------   1 taylor   taylor      24576 Aug 19 17:32 BIRTHDAY LIST.DOC
    drwxrwxr-x   3 taylor   taylor       1024 Aug 19 01:04 CNC
    -rw-r--r--   1 taylor   taylor    2461387 Sep 21 11:05 GraphicConverter 3.4 US.sea
    drwxrwxr-x   2 taylor   taylor       1024 Jul 15 14:57 Lists
    drwx------   2 taylor   taylor       3072 Sep 17 13:12 Mail
    drwxrwxr-x   5 taylor   taylor       1024 Sep 13 23:02 Src
    drwxrwxr-x   2 taylor   taylor       1024 Sep  3 10:59 Stuff
    drwxrwxr-x   2 taylor   taylor       1024 Apr 17 23:42 Talks
    drwxrwxr-x   2 taylor   taylor       1024 Sep  3 23:17 bin
    -rw-r--r--   1 taylor   taylor       1958 Sep 22 00:46 browsex.ksh
    -rw-------   1 taylor   taylor      11016 Jul 23 15:32 cooltools.com
    drwx------   2 taylor   taylor       1024 Apr  6 16:17 mail
    -rwx--x--x   1 taylor   taylor        921 Sep 16 11:49 invoice.sh
    -rw-rw-r--   1 taylor   taylor        502 Sep  9 07:51 taylor.cron
    226 Transfer complete.
    ftp> quit
    221 Goodbye.
    
  5. Wondering what applications are running while I'm using the MachTen environment? It's a real UNIX OS, so it manages its own task list:

    taylor 48 : ps -aux
    USER       PID  %CPU %MEM   SZ  RSS TT STAT  TIME COMMAND
    root         0  96.8  0.0   0K   0K ?  R <         (kernel idle)
    taylor     105   0.0  0.2  90K 151K w0 R     0:00 ps -aux
    root        68   0.0  0.2  53K 113K co U     0:00 /usr/sbin/macmntd
    taylor      76   0.0  0.2 102K 163K w0 S     0:00 -csh (csh)
    root        74   0.0  0.3 129K 189K co S     0:01 /usr/bin/wind
    root         1   0.0  0.2  91K 151K ?  S     0:01 /sbin/init
    

Although MachTen doesn't offer the nifty commands included with the MKS Toolkit to let your scripts look like Mac applications, it offers something much more powerful: a complete and robust UNIX operating system running within MacOS. It's a powerful combination.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset