Using mkfifo and netcat to redirect a file to a remote machine

From EggeWiki
Jump to navigation Jump to search

On a resource bound server we had an issue where there wasn't enough disk space or RAM to record the log files. Our vendor wanted a record of our logs, with the logging turned up to the max. The vendor's application is written in C and runs on Solaris.

As a work around to this problem, I decided to redirect the log file to a remote machine. Fortunately, the vendor's app writes to a well known file, and appends to the file if it already exists.

In the fashion of syslogd, I decided to replace the log file with a fifo pipe.

<geshi lang="bash"> $ mkfifo /logs/acos.log </geshi>

Next, I started a netcat listener on my Windows desktop under Cygwin. In the example below, I've simply written to stdout. In reality, I've filtered the output of netcat using grep, and bzip2 the data before writing it to a file.

<geshi lang="bash"> $ nc -l -p 12345 </geshi>

Next, I started up a netcat process to connect the fifo pipe to my desktop. <geshi lang="bash"> nc mywinhost 12345 < /logs/acos.log </geshi>

Lastly, I started up the vendor's program and watched as the log files travelled back to my local machine. Obviously, I wouldn't recommend doing this in production, as if either of the netcat processes stop, the vendors program will likely halt.