Thursday, October 15, 2009

connection between two systems without using ssh

While there are a myriad ways in which you can connect two systems, my colleague happened to bring up this question

As a build and release person, what options other than ssh do you have to run your scripts remotely on another system.

Hmm " Yeh to hamne kabhi socha hi nahi" , was the first reaction from all of us. My colleague then did a li'l bit of googling and came up with this thing called "netcat"(nc).

We worked on finding out how it worked. To a certain extent I could figure out how this works

We were working on Unix systems, so nc is generally installed by default
- log in as root on a machine that you want to execute the command in
- run "nc -l -p 32276" . you can add -v for verbose output. see man for more details. This will start an nc process that listens (l) to port (p) 32276
- on the machine from where you want to execute the command run
" nc "ip-address of server" 32276
- this opens a connection pipe over tcp/ip between the two systems and you can communicate between the two systems as you would do with a chat client. do a control-c at any one end and the connection breaks down

Now, if you want to execute a command at the remote end

- log in as root on a machine that you want to execute the command in
- run "nc -l -p 32276" | while read elem; do; $elem;done
- on the machine from where you want to execute the command run
" nc "ip-address of server" 32276
- this opens a connection pipe over tcp/ip between the two systems and you can typ[e in the command that has to be executed at the other end eg: ls, pwd etc... just replace the command with the path to your build script and there you have the build executed remotely.

Disclaimer: I have executed the commands and that seem to work well. Have not tried running build scripts