I’m currently learning Python, and as I’ve always found the best way to learn a new language is to use it, I decided to write a small script to give me a menu for hosts that I commonly SSH to.

I was roughly aiming to replicate a similar setup I have at work using FMLI on Solaris. My script is nowhere near as useful as FMLI, but might be useful to anyone trying to do similar (particularly as I found a real lack of Python/Curses documentation.)

The main script is available here: PyMenu.py

Configuration is via an xml file like the following:

<?xml version="1.0"?>
<menulist>
  <menuitem name="Laptop" command="ssh john@laptop" />
  <submenu name="Work Hosts">
    <menuitem name="Test1" command="ssh user@host" />
    <menuitem name="Test2" command="ssh user@host" />
    <submenu name="Production">
      <menuitem name="Prod1" command="ssh user@host" />
      <menuitem name="Prod2" command="ssh user@host" />
    </submenu>
  </submenu>
</menulist>

Just add items with a name and system command to run (in my case SSH). Nested submenus are also possible. Once you’ve created your menu.xml file, just run with ‘PyMenu.py menu.xml’ then move to the entry you want (either using the up and down arrows, or the number keys) and hit enter to run the command.

See it in action

Share or bookmark this post:
  • Digg
  • Reddit
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • description

Comments RSS

No Comments

No comments yet.

Leave a Comment