Scripting technology demonstrations in (Open)Solaris

Several folks have asked me to post the demo scripts and tools I use when presenting (Open)Solaris talks that contain live demonstrations. Initially I hesitated, primarily because these scripts and tools are embarassingly simple. Yet, because I was asked by several of folks, I decided to post them here. If you make improvements to these tools or scripts, please send me the code as I am planning on continuing to use (and document improvements of) this approach until I find something better.


The Demo Building Blocks Explained

The scripts were developed on and for OpenSolaris, however, the basic technology should work on any Unix system. I tried them on Mac OS-X and Solaris 10, update 5 without any problems. There are two compiled C-programs, one called typer, the other one called wait4enter. I am including the source code and Makefiles - the tar ball with all the software also contains precompiled versions for OpenSolaris 2008.05 and for Mac OS-X.:

These programs do just what their names promise.

  • After you execute wait4enter in a shell, the program waits for you to hit [ENTER], then exits.

  • After you execute typer with command line arguments, it prints the command line arguments to the screen, one character at a time, in a speed that let's the observer easily read along. (In fact, at times it seems to be typing too slowly, but since this is a tool for demos, I usually take my time explaining the meaning of the shell commands that are being printed to the screen.) And should you execute typer without command line arguments, well... the program returns immediately.

These two building blocks are enough to create powerful demo scripts using your favorite scripting language. I had started with borne shell scripts in the desire to remain compatible by using the least common denominator, but quickly switched to PERL...

Let me give you a few examples just how to use these tools in a perl script. At the end of the article I am posting the demo scripts I used during my Tech Days presentations in Mexico City, Mexico and Manila, Philippines for the IPS (Solaris Image Packaging System) demo and in São Paulo, Brazil for the Solaris Security demos (Solaris Privileges, Solaris Role-Based Access Control, and the Solaris Cryptographic Framework.)

From now on I assume you have typer and wait4enter in your path and your perl interpreter is in /usr/bin. I am using Perl version 5.8.4, but I am sure it would work with older versions of Perl as well.

A first example (tmpdemo):  

#!/usr/bin/perl -w

$prompt = "\\$";

sub command {
  printf ("$prompt ");
  system ("typer \\"$pcmd\\"");
  system(wait4enter);
  system($xcmd);
  printf("$prompt ") ; system(wait4enter);
}

#--------------------------------------------------
# main

system(clear);
  $pcmd="whoami";
  $xcmd=$pcmd;
  command();
#--------------------------------------------------

This  program would type out the command whoami, execute it once [ENTER] is depressed, then wait in a prompt until [ENTER] is pressed again, then exit.

If this does not seem very spectacular, imagine the following. You are standing in front of 800 people and want to execute an intricate set of commands in the right sequence,  some of them possibly with many command line arguments that are easily mistyped, while concurrently explaining what the arcane symbols mean that you are trying to find on the strange keyboard in front of you... Program typer suddently seems like a fine tool to use, don't you think?

Here a short list of a few more features and capabilities that might not be obvious at first sight:

  • You can include programs to be executed that need to be interactively stopped using \^D or \^C.
  • You can execute several demo scripts in different shells concurrently and have them interact.
  • You can print something different with the typer program than what's executed. This feature is especially useful to hide some command line arguments that are necessary, but that you do not want to focus on when explaining what is happening. This feature also enables you to avoid getting into - what I call - "escape sequence hell" in Perl programming. If you have ever done any significant Perl programming you know what I mean; if not, I won't explain it here, just envy your for your protected upbringing. 

Here is an example that illustrates these features:

In a first shell you would execute a demo script (tmpdemo0) with:

  $pcmd="tail -f /var/adm/messages";
  $xcmd=$pcmd;
  command();
And in a second shell you would execute a demo script (tmpdemo1) with:
  $pcmd="ppriv -e -D cat /etc/shadow";
  $xcmd="date;$pcmd"; 
  command();
Then you would \^C the tail command in the first shell and the first demo script would continue.


Combining Demo Scripts With VirtualBox Hosted OS Images 

While it is perfectly fine to execute demo scripts directly within the OS that you are running on your presentation machine, I typically take a different approach: I run demos in the context of a second instance of the operating system hosted under the VirtualBox type-2 hypervisor. There are a number of good reasons why I setled on this option:

  • I typically run demos that modify core system configuration, such as security attributes or which software is installed. Making these modifications on my core OS would require me to back them out carefully every time I've run my demo to reestablish the machine state the way it should be at the beginning of the demo. Hosting the OS in VirtualBox allows me to start the demo every time with the same identical OS snapshot, to discard all modifications that have been made by the demo, and to return to the snapshot at the click of one button.

  • This approach allows me to have different demos "up my sleeve" that might require quite different OS setups, leave alone completely different versions of the same OS or different OSes altogether.

  • This approach allows me to share demos with others who might want to present them.

  • Because the VirtualBox VDI images are platform-independent, it is trivially possible to demonstrate OpenSolaris on any platform OS that VirtualBox runs on (such as Mac OS-X, Windows, and many flavors of Solaris and Linux.)

  • Because I use OS snapshots, startup of the demo OS and script are very fast. No waiting for an OS to boot and no need to set up a number of shells, start apps, etc. A snapshot can capture all of that. This benefit is especially useful if you want to present a number of different demos back to back.

  • And (for the pack rats amongst us), it allows me to archive demos for future use or reference.

I had planned to post these demo scripts together with the VirtualBox VDI images of OpenSolaris that I was using, but since they are all using the same vanilla, virgin installed OpenSolaris release 2008.05, I refrained from that.

Here are the promised links to the demo examples. Go wild and please post a comment to this blog if you are using these tools successfully or if you have suggestions for improvements.

And finally, the tar-ball with all demo utilities and precompiled binaries typer
and wait4enter for OpenSolaris 2008.05 and Mac OS-X can be downloaded here:

Comments:

Thanks for that Chris, regards

Posted by Mauricio Nogueira on October 10, 2008 at 01:10 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

user9159837

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today