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";

Friday, July 19, 2013

non-existent remote syslog server causes SSH and su to pause/hang

I recently setup a VMware lab for a project at work. As a quick start, I used some of our existing kickstart deployments (actually using cobbler), which included a bunch of operational configuration items.

Soon my users were experiencing some issues on logging in via SSH. The symptom was one of the following would occur:

  • User would immediately get the error "ssh_exchange_identification: Connection closed by remote host"
  • User would have to wait ~20 seconds to get a password prompt. After entering a password, another ~20 seconds would pass before getting the shell prompt.

I did a lot of different things to try to find the problem. I found that rebooting the system resolved the issue temporarily. Exacerbating the issue was that only a couple systems were experiencing the problem -- not all of them. So at first I discounted it being an issue with the configuration of the system. I chased the red herring of a certain application we were running on *only* those systems.

Another symptom of the issue was that "su" would also pause for ~20 seconds before presenting the password prompt, so I knew it wasn't limited to sshd.

Eventually I found the problem by doing the following:

 # strace su -
[...]
###  The output would pause here:
    connect(3, {sa_family=AF_FILE, path="/dev/log"}, 110) = 0
    sendto(3, "<86>Jul 19 16:36:59 su: pam_unix"..., 96, MSG_NOSIGNAL, NULL, 0) = 
/dev/log is a UNIX domain socket, used by the syslog (and rsyslog) daemons. The system was trying to write to the socket, and it was taking a long time.

When I looked at the config file (/etc/rsyslog.conf), I found that it had been setup to log to a remote server on our production network. Of course, the lab did not have access to the production network! So rsyslog was trying to log to a non-existent system.

The fix was simply to remove the non-existent remote syslog server from rsyslog.conf and restart syslog.

Why didn't *all* the lab systems have the same problem? I believe this is because the "problem" systems had much more syslog messages than the other systems -- due to the application we were running on those systems. So it was only indirectly related to the application!

Friday, June 28, 2013

mental health

I had a very weird encounter at the Community Center gym this evening. While I'm jogging on the treadmill, a guy approaches me and says something. I didn't understand what he said because of my headphones and all the noise -- but he seemed to be trying to hand me some kind of flyer. I took it and started reading it; he seemed satisfied and walked away.

The flyer was some silliness about "cleansing" your body every month with cabbage or something, so I stopped reading and put it aside so I could concentrate on the Science podcast I had been listening to.

I had assumed our encounter was over, but he had taken the machine right next to my treadmill. When I accidentally dropped the baseball cap I use to keep my hair out of my face, I decided to stop running long enough to pick it up. That's when he verbally pounced on me.

"You know the government doesn't like me passing out those flyers."

Oh shit here we go, I thought. "What do you mean, the government?" I wanted to distinguish between police officers, NSA, etc. but I guess I wasn't clear.

"You don't know who the government is?" he seemed surprised.

"I mean, I don't understand why anyone would care about you passing out these flyers." Why am I still talking to this guy?

I don't remember exactly what he said, but it was something like "They like to brainwash people. You ever hear of mind-control devices?"

The dubious expression on my face must've given me away because he seemed to be upset or hurt that I didn't believe him. He took his flyer back, saying I didn't deserve it or respect him. As he walked away I tried to ignore him and resume listening to my podcast.

But he didn't leave the gym right away, and I was a bit uncomfortable every time he walked by me, worried he'd try to to talk to me again. He soon left the gym, though, and I relaxed again.

After I finished jogging, I saw I was alone in the gym with a woman riding one of the upright stationary bikes. I thought perhaps I should warn her about this guy. I apologized for interrupting her workout, and briefly told her how he had talked about his flyer, and his paranoid thoughts about brainwashing and mind-control devices from the government. She told me he had tried to give her a flyer but she refused it. He didn't bother her after that.

As I continued my workout and started thinking more about the guy, my selfish annoyance changed to (slight) concern. I had seen him around the Community Center a few times -- usually in the gym, or as I walked past him with the dog as he sat on one of the benches around the man-made pond at the Center, smoking a cigarette. (Hey at least he works out... and apparently "cleanses"). He had never talked to me before, though.

Why today, though? Was this a way for him to call out for help? Should I tell "the government" about him? I realized that even had I the will to help him, I hadn't the slightest idea how to go about it. If he had a broken ankle, I could call an ambulance for him. But a slightly broken psyche? Unless he's threatening someone or himself, the 911 personnel would probably laugh at me.

I don't think this guy is going to hurt anyone -- but that doesn't mean he doesn't need help. If you have any thoughts about this please comment.