views:

260

answers:

4

I have some applications, and standard Unix tools sending their output to named-pipes in Solaris, however named pipes can only be read from the local storage (on Solaris), so I can't access them from over the network or place the pipes on an NFS storage for networked access to their output.

Which got me wondering if there was an analogous way to forward the output of command-line tools directly to sockets, say something like:

mksocket mysocket:12345
vmstat 1 > mysocket 2>&1
+5  A: 

netcat will help establish a pipe over the network.

Chris
+5  A: 

Netcat is great for this. Here's a page with some common examples.

Usage for your case might look something like this:

  1. Server listens for a connection, then sends output to it:

    server$ my_script | nc -l 7777

  2. Remote client connects to server on port 7777, receives data, saves to a log file:

    client$ nc server 7777 >> /var/log/archive

tgamblin
thanks, and thanks for the examples!
Robert Gould
+1  A: 

You may want to use one of:

  1. ssh: secure (encrypted), already installed out-of-the-box on Solaris - but you have to set up a kepair for non-interactive sessions
  2. netcat: simple to set up - but insecure and open to attacks
vladr
thanks for the ssh answer, in this case security isn't an issue, but its good to have it here in the question
Robert Gould
+5  A: 

netcat (also known as nc) is exactly what you're looking for. It's getting to be reasonably standard, but not available on all systems.

socat seems to be a beefed-up version of netcat, with lots more features, but less commonly available.

On Linux, you can also use /dev/tcp/<host>/<port>. See the Advanced Bash-Scripting Guide for more information.

Brian Campbell