MarginalHacks.com DaveSource.com
serverizor
 

What is it?

This allows you to take a normal command-based program (such as telnet, rlogin, ftp) and run it as a tcp server in the background.

This means that you can start up such programs once, and then connect to them with a command-line client (the same script, actually), and run commands, disconnect, connect again from some other machine, etc.. etc..

As a more concrete example, you can use it to boot up a large program such as emacs or lisp (in interpretor mode, not in editor/windowing mode) in the background, and then whenever you want to run emacs/lispy scripts you could just run a serverizor client with a few commands. Bingo!

The client and the server are the same program. Consider it to be like an intelligent client - it will start a server in the background if it needs one.

License:

This software is essentially free, but please read my payment spiel
Please read the full license

Examples:

Lets say I want to have a telnet session open to another machine that I want to be able to occasionally run commands on (like rsh, but with a single login and no .rhosts).

Come up with a regexp that will match (only) your shell prompt, such as '^\d+% ' and then call:

  % serverizor -daemon="telnet some_host" \
               -prompt='^\d+%'
               -watch='^login: '==some_user \
               -watch=^Password:==some_pass \
We choose the program and the prompt that we want to watch for that lets us know that we can take another command. We also setup some -watch prompts that will let us automatically login.
The first time we run the command it needs to actually startup the daemon and get to the first prompt, so it will ask you to wait for this. It will start up a server for you in the background, and start up a client that will wait to connect.
Once you have actually connected, you can start typing in shell commands. Each command line needs to return to the prompt though, so commands that take over the input, such as "vi" or even a plain "cat > file", will screw up the serverizor. If you need to do that, consider adding -watch prompts to handle the non-prompt lines.
If you type "exit" then you'll actually end the telnet program which will shut down the server and client. If you want to just end the client, you can disconnect with "." on a line by itself, with eof (control-D) or an interrupt (generally control-C).

What's particularly cool about this is that you can run the client as a command-line option. As an example, start up just the server (with -start_server or else by disconnecting the first client that comes up). Then you can run a single command with:

  % echo "ls" | serverizor 

This will not only run "ls" on the telnet shell, but will wait until it's received the entire response of the ls and then disconnect, leaving the shell waiting at the next prompt for the next client.

As another example, we can use serverizor to put an ftp session in the background:

  % serverizor -daemon="ftp some_host" \
               -prompt="ftp> " \
               -watch='^Name \(.*\): '==some_user \
               -watch=^Password:==some_pass
Same basic idea, just different prompts.

Play around with it - but make sure you kill off any serverizors that you launch in the background with -stop_server. And if you don't change the port when you change commands, then serverizor will connect to the old server and get very confused.

process ids of servers are saved in /tmp/pid.serverizor* as a default.

Download:

It's a single perl script.

Requires:

  1. Perl, which kicks ass
  2. Expect.pm of at least v1.08

Install

It's just a perl script. No install required.

serverizor?

Yea, yea, I know. I'll happily take suggestions for a new name.

Revision History:

See the CHANGELOG

Freshmeat?

You bet.