Sunday, June 1, 2014

Perl script to quiz you for ARRL Ham radio exam

I've been studying for the Technician class amateur radio license. The ARRL sells a book that includes a CD with some nice software for practicing tests. However, if you don't have the book and/or CD, you might want to practice the test questions anyway. So I wrote a perl script that reads the text version of the question pool ( 2010 version or 2014 version), then asks you questions from it. example run:
# study.pl ~/Downloads/question_pool.txt

enter question # (blank for random question) or Ctrl-C to exit :

T6B07
What does the abbreviation "LED" stand for?
A. Low Emission Diode
B. Light Emitting Diode
C. Liquid Emission Detector
D. Long Echo Delay


answer? A
*** WRONG!      correct answer is (B)

enter question # (blank for random question) or Ctrl-C to exit :

T7A07
If figure T5 represents a transceiver in which block 1 is the transmitter portion and block 3 is the receiver portion, what is the function of block 2?
A. A balanced modulator
B. A transmit-receive switch
C. A power amplifier
D. A high-pass filter


answer? b
CORRECT!
Download the script

Thursday, April 3, 2014

Automating the VMware vSphere Perl SDK install with expect:


I couldn't find any other postings on the net about this, so here's my solution for automating the installation for the VMware vSphere Perl SDK on RHEL6 (this assumes you already have all the prerequisites installed.).  It probably works on any Linux OS but I only tested it on RHEL6.4.

Save this expect script (requires expect to be installed, duh!) in the same directory as the extracted tarball for the SDK (probably vmware-vsphere-cli-distrib/):
#!/usr/bin/expect

set timeout 120

spawn "./vmware-install.pl"

expect "Press enter to display " { send "\r" }
expect "vSphere Software Development Kit License Agreement" { send "q" }
expect "Do you accept" { send "yes\r" }
expect "Do you want to install precompiled Perl modules for RHEL" { send "\r" }
expect "In which directory do you want to install the executable files" { send "\r" }
# Wait for installation to finish
expect EOF
This accepts the defaults ("yes" to installing precompiled perl modules, "/usr/bin" for the installation directory) If you don't like that, edit the script!

SSH tunnel to multiple vSphere/ESXi hosts

An SSH tunnel to a single host is easy; reference: http://www.virtuallifestyle.nl/2010/03/tunneling-a-vsphere-client-connection-over-ssh/

However, if you want to open the vSphere client multiple times for simultaneous connections to multiple ESXi/vCenter hosts, then you have to get a little creative. Basically you follow the same instructions as above, except you don't need to edit the hosts file. Just use a single address in the loopback network (127.0.0.2 - 127.255.255.254 ) for each remote ESXi host.  e.g.:

ESXi host Tunnel Source Tunnel Destination
host1 127.0.0.2:443 esxhost1:443
host1 127.0.0.2:902 esxhost1:902
host1 127.0.0.2:903 esxhost1:903
host2 127.0.0.3:443 esxhost2:443
host2 127.0.0.3:902 esxhost2:902
host2 127.0.0.3:903 esxhost2:903

Then simply connect vSphere client to one of the loopback addresses you used.  In the example above, to connect to esxhost1, you connect vSphere Client to 127.0.0.2.  For esxhost2, 127.0.0.3.

You should be able to make up to ~16 million tunnels this way!

NOTE: When using an SSH tunnel, the vSphere Client will not show the "Hardware" tab for your hosts.