1

I have a python script that output/prints a large array (50MB in size) to the screen. This script is running on machineA. Is it at all possible to 'pipe' this output to machineB, where it will be processed?

I know I can save the output in a file on machineA and then send the file to machineB. I was just wondering if it is possible to do so without having to save the data first to a file (on machineA).

Any solutions (python, bash shell, other ideas) will be appreciated.

5 Answers 5

6

This is a work for nc (netcat)... on machineB you do

nc -l 12345 | processing_program

This command will start netcat in "listen mode" waiting for a connection. Once the connection is established what is coming from the network will be sent to stdout and what is sent to stdin will be sent back to whoever connected.

After that you go on machineA and run

generating_program | nc machineB 12345

this will instruct netcat to start a connection to machineB (port 12345) and send whatever it gets from stdin over the wire. Whatever comes back from that connection is sent to standard output.

Sign up to request clarification or add additional context in comments.

3 Comments

Your answer is better (no need for passwords, or for running a service).
6502: thank you. can machineB be listening to 20 machines at the same time? also, must I actively 'open the listening port' on machineB?
With that command machineB will be listening to whoever connects (so this is of course not secure at all... anyone on the internet without any authentication can send data to processing_program using machineB if that machine can be reached!). nc terminates once the client closes the connection so you will eventually need to rerun the command in a loop. If for "opening the listening port" you mean making an hole in your firewall or defining a virtual server path in your router the answer is yes. nc simply does a TCP listen on the specified port.
2

On machineA:

python script-on-machineA.py --options | ssh machineB tee /file/on/machine/B.txt

Alternatively, on machineB:

ssh machineA python /path/to/script-on-machineA.py --options | cat > /file/on/machine/B.txt

1 Comment

This would work well, since I can easily SSH between the machines.
1

With the Netcat tool you may easily pipe data from one machine to another.

Comments

1

You can do it on different levels - here are a few options

  1. use ssh to pipe myprog | ssh remotemachine myotherprog
  2. use nfs (if going to a file
  3. use netcat (nc)
  4. use something like thrift

It depends on how solid & permanent the solution needs to be

Comments

1

Maybe something along the lines of

myPythonScript | ssh user@machine "sh -c 'cat >myfile.txt'"

WARNING: pulled entirely out of my head and untested!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.