A standard Unix command-line tool for piping to a socket

Robert Gould picture Robert Gould · Feb 23, 2009 · Viewed 28.6k times · Source

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

Answer

Todd Gamblin picture Todd Gamblin · Feb 23, 2009

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