Damon Cortesi's blog

Musings of an entrepreneur.

Running Tentakel on Windows

| Comments

Nothing like a little late-night Python to keep one up until the wee hours of the morning…

I came across a great article tonight about executing commands on multiple nix servers. It will come in extremely handy for me when moon-lighting as a nix admin. I’d used fanterm before, but it wasn’t that good looking and being the freak of nature that I am, I spend most of my time in Windows. Although the program mentioned in the above article, Tentakel appeared to be designed for use on Linux systems, it is written in Python and should be able to run on Windows.

Well I can confirm that it does, but it needs a few changes in order to do so. What follows is a brief overview of the changes needed and then some more detailed descriptions about what was done. To get Tentakel working on Windows, follow these steps (current as of Tentakel 2.2):

  1. Comment out
    1
    
    import pwd
    in lekatnet\config.py
  2. Modify the
    1
    
    user
    parameters on lines 62 and 349 to be the user you’re going to connect as, ie: ‘user’: “bob”, user1 = “bob”
  3. Set a HOME environment variable: set HOME=”C:\Documents and Settings\bob\My Documents”
  4. Finally add
    1
    
    import os
    at the end of the imports list in lekatnet\plugins\ssh.py and
  5. Either comment out or delete the status, output = commands.getstatusoutput(s) (line 43) in the same ssh.py and add the following where it was:
    1
    2
    3
    
    pipe = os.popen(s + '2>&1')
          output = pipe.read()
          status = pipe.close()
    and then change the return statement to not perform the shift:
    1
    
    return (status, output)

Follow those instructions, create your tentakel.conf and you should be good to go. By the way, I used the wonderful plink for my ssh client:

1
set ssh_path="C:\Download\Net\plink.exe"

Now for the gory details.

After unpacking the source, I just attempted to run the program to see what would happen.

C:\tentakel-2.2\py>python tentakel Traceback (most recent call last): File “tentakel”, line 43, in ? import lekatnet.config as config File “C:\tentakel-2.2\py\lekatnet\config.py”, line 53, in ? import pwd ImportError: No module named pwd

Hrm, looks like it’s using a module that my Python install doesn’t have. Looking a little bit deeper, this module is actually used to retrieve passwd information from /etc/passwd. In this case, it’s retrieving the current users effective user id. Well…no need for that, really. Just comment out the

1
import pwd

and change the two areas on config.py where the pwd.getpwuid is referenced to be a static string of my username.

Try to run it again:

C:\tentakel-2.2\py>python tentakel Traceback (most recent call last): File “tentakel”, line 43, in ? import lekatnet.config as config File “C:\tentakel-2.2\py\lekatnet\config.py”, line 68, in ? __user_dir = os.path.join(os.environ[‘HOME’], ‘.tentakel’) File “C:\Python24\lib\os.py”, line 422, in __getitem__ return self.data[key.upper()] KeyError: ‘HOME’

Ah…Windows doesn’t generally set a HOME environment variable. No problem there, just do it myself. set HOME=”C:\Documents and Settings\bob\My Documents”

Tentakel ran ok after that with the provided -h flag to get a usage display. Next I made a config file and tried to run it:

C:\tentakel-2.2\py>python tentakel -c tentakel.conf -g linuxservers uptime ### t.u.x.y(stat: 0, dur(s): 2.0): ’{’ is not recognized as an internal or external command, operable program or batch file. ### t.u.x.z(stat: 0, dur(s): 2.42): ’{’ is not recognized as an internal or external command, operable program or batch file.

That certainly doesn’t look good. My first guess was that it was executing the command in those braces, which is compatible on *nix, but not Windows. The only problem was…I didn’t know where this was getting executed. An hour of debugging and familiarizing myself with both python and the tentakel program, and some googling led me to line 43 in lekatnet\plugins\ssh.py:

1
status, output = commands.getstatusoutput(s)

. It appears that the getstatusoutput function uses unix-specific command syntax. That google groups link gives a couple suggestions and I ended up using the last one. I added

1
import os

at the end of the imports list at the beginning of ssh.py and replaced the line above with the following:

1
2
3
pipe = os.popen(s + '2>&1')
      output = pipe.read()
      status = pipe.close()

and then finally modify the return statement to not perform the shift:

1
return (status, output)

Save all the files and Tentakel works beautifully in Windows. From a second look, it’s not quite as nice as fanterm in that it is not truly interactive…but I think it’ll do just fine. My only gripe now is that output is based on the duration of the command…something to keep in mind when glancing quickly at the output.

Comments