Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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 
like image 990
Robert Gould Avatar asked Feb 23 '09 07:02

Robert Gould


People also ask

What is the use pipe line command in Unix?

Pipe is used to combine two or more commands, and in this, the output of one command acts as input to another command, and this command's output may act as input to the next command and so on. It can also be visualized as a temporary connection between two or more commands/ programs/ processes.

What is piping in command line?

You use piping to filter the contents of a large file—to find a particular string or word, for example. This purpose is why the most popular use for pipes involves the commands grep and sort . But, you're not limited to those cases. You can pipe the output to any command that accepts stream input.

What is called piping in Unix?

In Linux, the pipe command lets you sends the output of one command to another. Piping, as the term suggests, can redirect the standard output, input, or error of one process to another for further processing.

How is pipe created in Unix?

A pipe can be explicitly created in Unix using the pipe system call. Two file descriptors are returned--fildes[0] and fildes[1], and they are both open for reading and writing.


1 Answers

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

like image 103
Todd Gamblin Avatar answered Oct 04 '22 17:10

Todd Gamblin