Tuesday, January 27, 2015

linux: how to determine if a binary is prelinked

On my systems I use aide to find changes to the system. On one of them, aide was complaining:

WARNING: AIDE detected prelinked binary objects on your system but the prelink tool (/usr/sbin/prelink) is missing!
WARNING: prelinked files will be processed without a prelink undo operation! Please install prelink to fix this.

This is because at one point, I did in fact use prelink. However, I had many issues with aide and prelink and finally just got fed up and removed it. Before doing that you're supposed to undo the prelink, but apparently I missed a file. But aide didn't tell me which one! I couldn't find any information on the net about how to determine whether a binary is prelinked, so here's the answer:

readelf -S | grep prelink

If the binary is prelinked, you'll get something like:

[30] .gnu.prelink_undo PROGBITS 0000000000000000 000e4790

But what if you don't know which file is prelinked? And /etc/prelink.cache is non-existent (because someone removed it) or empty? In that case, you have to examine every ELF binary on the system. I elected to break this into two steps. First, find all the ELF binaries:

find / -type f ! -path "/sys/*" ! -path "/dev/*" ! -path "/proc/*" \
! -path "/opt/splunk/var/*" ! -path "/mnt/*" ! -path "/media/*" ! -path "/srv/*" \
! -path "/net/*" ! -path "/selinux/*" | xargs file | grep ELF | cut -f1 -d':' \
> /tmp/elffiles

Now that you have a list of all the ELF binaries, test each of them to find out if they are prelinked. I did not use xargs in this case because although readelf works on multiple files, when combined with grep it would be hard to tell which of the arguments in the long argument list is the culprit:
for file in $(cat /tmp/elffiles) ; do
   readelf -S $file | grep -q prelink
   if [ $? -eq 0 ]; then echo $file is prelinked ; fi
done

I realize the above doesn't handle paths with spaces or other weird characters. I guess I'm lucky my system didn't have any of those.

Wednesday, January 14, 2015

Dell PERC command-line utility program perccli

This tool apparently works for all PERC9 controllers and the following operating systems are supported:
Novell SuSE Linux ES 11 
MS Windows Server 2012 
Red Hat Ent Linux 6 
Red Hat Ent Linux 7 
SUSE Linux ES 12 
MS Windows Server 2012 R2/SP 
MS Windows 2008 R2

Binaries are at: http://www.dell.com/support/home/us/en/19/Drivers/DriversDetails?driverId=3XDPP

HTML version of manual: http://www.dell.com/support/Manuals/us/en/19/Topic/poweredge-rc-h730/PERC_CLI_RG_Pub-v1/en-us

PDF of manual: http://topics-cdn.dell.com/pdf/poweredge-rc-h730_Reference%20Guide_en-us.pdf

Monday, January 5, 2015

Phonetic Alphabet of Confusion

I wanted to make a phonetic alphabet chart, but with words that all have the "wrong" sound at the start. e.g.A as in "aisle" I shamelessly stole most of this from

http://www.reddit.com/r/videos/comments/2g3fcw/i_had_another_phone_scammer_try_to_call_me_so_i/ckfs07x

I'd wanted to use words instead of names if possible (e.g. for "I", I'm used "Ian" because I couldn't find a word that starts with I but has an "e" or other sound.)

I thought about going through the Wiktionary database but that will take a while to program maybe...

Anyway, here's what I have so far:

A - aisle
B - bdellium
C - czar
D - djinn
E - euphrates
F - effluent (I would prefer a word that starts with "F")
G - gnome
H - honor
I - Ian  (can you think of a word not a proper name?)
J - jalapeno
K - knickers
L - elephant (I would prefer a word that starts with "L")
M - mnemonic
N - Nguyen (resorted to foreign language here :( )
O - ouija board
P - pterodactyl (bonus:  P sounds like T ) 
Q - qat
R - arse (I would prefer a word that starts with "R")
S - schadenfreude (can you think of a non-foreign word that starts "sch"
but sounds like "ch"?)
T - Tsunami (foreign origin, but has been adopted as English so I don't
feel bad about this one)
U - urn
V - vrow (frau) (optionally "vee") 
W - wren
X - Xian  (X is weird anyway, most words sound like "Z" anyway, so I
went with an "Sh" sound (Shee-an) instead! but again - it's a foreign
name, can't think of a word)
Y - yperite
Z - Zsa Zsa  (proper name :( )

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.

Monday, November 25, 2013

Perl script to convert JPL Horizons Ephemeris data to Celestia SSC Elliptical Orbit Parameters

With Comet ISON coming up, I've been playing with Celestia a bit to see if I can get it to show me with reasonable accuracy where the spacecraft SDO and STEREO (-A and -B) are in relation to the comet.

Long story short -- I had to make my own Celestia ".ssc" files to describe the spacecraft. Using the JPL HORIZONS web interfaceyou can get recent orbital elements, but you have to convert these to something Celestia will understand (an "EllipticalOrbit" stanza in the ".ssc" file).

The perl script below does the conversion; just run it and paste in a single block of Ephemeris data like this:

2456621.500000000 = A.D. 2013-Nov-25 00:00:00.0000 (CT)
 EC= 4.143129880700237E-02 QR= 9.996672652291025E-01 IN= 2.936558964716465E-01
 OM= 3.363978705358475E+02 W = 1.469845587993808E+02 Tp=  2456458.185749091208
 N = 9.254559117051611E-01 MA= 1.511401389693867E+02 TA= 1.533315740323342E+02
 A = 1.042874927988944E+00 AD= 1.086082590748784E+00 PR= 3.889974610856358E+02
And you'll get output line this:
EllipticalOrbit
{
        Epoch 2456621.500000000
        Period 1.06499689086802
        SemiMajorAxis 1.04287492798894
        Eccentricity 0.041431298807
        Inclination 0.293655896472
        AscendingNode 336.397870535848
        ArgOfPericenter 146.984558799381
        MeanAnomaly 151.140138969387
}
The perl script is below, or you can download it here.
#!/usr/bin/perl -w

# input an ephem set like this:
#2456621.500000000 = A.D. 2013-Nov-25 00:00:00.0000 (CT)
# EC= 4.143129880700237E-02 QR= 9.996672652291025E-01 IN= 2.936558964716465E-01
# OM= 3.363978705358475E+02 W = 1.469845587993808E+02 Tp=  2456458.185749091208
# N = 9.254559117051611E-01 MA= 1.511401389693867E+02 TA= 1.533315740323342E+02
# A = 1.042874927988944E+00 AD= 1.086082590748784E+00 PR= 3.889974610856358E+02

# output like this:
#        EllipticalOrbit
#        {
#                Epoch 2456621.500000000 # = A.D. 2013-Nov-25 00:00:00.0000 (CT)
#                # reference http://www.lepp.cornell.edu/~seb/celestia/transforming_ephemeris.html
#                Period 1.06499689086801936 # P = (q/(1-e))^1.5 for a closed, elliptical orbit (q = QR, e = ER)
#                SemiMajorAxis 1.04287492798894325 # a = (q+Q)/2, where Q is Apoapsis distance (AD in horizons ELEMENTS)
#                Eccentricity 0.04143129880700237 # (EC)
#                Inclination 0.2936558964716465 # (IN)
#                AscendingNode 336.3978705358475 # (OM)
#                ArgOfPericenter 146.9845587993808 # (W)
#                MeanAnomaly 151.1401389693867 # (MA)
#        }

my ($Epoch, $EC, $QR, $IN, $OM, $W, $Tp, $N, $MA, $TA, $A, $AD, $PR);
my ($Period, $SemiMajorAxis);


print "Input a single block of ephem data\n";

while () {
        if ( /^((\w|\.)+)/ ) {
                $Epoch = $1;
        }

        if ( /EC=/ ) {
                ($EC, $QR, $IN) = (split())[1,3,5];
        }

        if ( /OM= / ) {
                #$_ = readline; chomp;
                ($OM, $W, $Tp) = (split())[1,4,6];
        }

        if ( /N = / ) {
                #$_ = readline; chomp;
                ($N, $MA, $TA) = (split())[2,4,6];
        }

        if ( /AD= / ) {
                #$_ = readline; chomp;
                ($A, $AD, $PR) = (split())[2,4,6];
                last;
        }
}

$Period = ( $QR / (1 - $EC) )**1.5 ;
$SemiMajorAxis = ( $QR + $AD ) / 2 ;

print "EllipticalOrbit\n";
print "{\n";
print "\tEpoch $Epoch\n";
print "\tPeriod $Period\n";
print "\tSemiMajorAxis $SemiMajorAxis\n";
print "\tEccentricity " . sprintf("%12.12f\n",$EC);
print "\tInclination " . sprintf("%12.12f\n",$IN);
print "\tAscendingNode " . sprintf("%12.12f\n",$OM);
print "\tArgOfPericenter " . sprintf("%12.12f\n",$W);
print "\tMeanAnomaly " . sprintf("%12.12f\n",$MA);
print "}\n";