Scripting technology demonstrations in (Open)Solaris - V.2


This blog entry represents an update to my earlier blog on "Scripting technology demonstrations in (Open)Solaris". I created this entry, because I rewrote the software to include new functionality and to no longer require a C compiler. Everything's in Perl now. Some of the text below is duplicated from my original blog entry, but I figured it's easier on readers to find all information in a single blog entry rather than having to jump back and forth. For the impatient readers, here's what's new:

  • Ease of portability: demotools are now completely written in Perl - no more C programs that require compilation
  • The demo tools routines are a Perl module now, easily integrated into your program

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. The two most interesting functions are encapsulated in a Perl module called demotools.pm. One is called wait4enter, the other typer and they do just what their names promise:

  • After you call demotools::wait4enter,  your Perl program waits for you to hit [ENTER], then continues.

  • After you call demotools::typer with one arguments, the function prints its argument to the screen, one character at a time, in a speed that let's the observer easily read along.  You can change the speed by calling demotools::setdelay(delay_in_seconds). The default is 0.15 seconds delay. This delay seems about right for me, because I usually take my time explaining the meaning of the shell commands that are being printed to the screen.  Should you call typer without arguments, well... the function returns immediately. When debugging new demo scripts I usually reduce the typer delay to 0.01, as it can be quite annoying having to wait for long commands to be printed to the screen.

Both these functions are usually not called directly though. I created function demotools::cmd() that works as follows:

  • Give it no arguments - nothing happens.
  • Give it one string argument and it gets typed to the screen using typer, followed by a call to wait4enter, followed by executing the line, followed by a call to wait4enter.
  • Should you call demotools::cmd() with more than one argument, it prints the first, but executes all subsequent commands.

These building blocks are enough to create powerful demo scripts using Perl. As you can see from my earlier blog post on the subject, I had started with borne shell scripts with C programs implementing the functionality of typer and wait4enter 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 modified 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 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

use demotools;

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

  system("clear");
  demotools::cmd("whoami");

#--------------------------------------------------

Those of you who looked at my earlier blog post will notice how this demo script is significantly shorter than the original tmpdemo... That's because the common demo functionality is now located in the Perl module demotools.pm. 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... Function demotools::cmd() 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 demotools::cmd() function 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:

  demotools::cmd("tail -f /var/adm/messages");

And in a second shell you would execute a demo script (tmpdemo1) with:
  demotools::cmd("ppriv -e -D cat /etc/shadow", 
                 "date;ppriv -e -D cat /etc/shadow");
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:

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