Linux   Linux – TCP listener daemon with tcpserver

To configure passive checks in Nagios/icinga I use a tcp listener daemon that launches a script (See Nagios – Using passive checks without agent)
Tried to use inetd superserver daemon, but in the last versions, i have not been able to make it work correctly (See last update in my post: Linux – cannot found / missing inetd.conf)

Anyway I have been able to workaround the problem by using another simple method: tcpserver tool.

This tool, tcpserver, waits for connections from TCP clients. For each connection, it runs a program that is set as parameter.

We will use the same example as I explained in this post (Linux – Create custom inetd service)


The tcpserver will execute this simple script in this example. The script receives text through stding, executes the received command and prints the ouput.

This could be our script ( for example):


echo "Command [$MESSAGE]"
echo "-----------------"

Give executions perms:

# chmod +x /root/SCRIPTS/

Install tcpserver tool

In debian, tcpserver tool is included in the ucspi-tcp package

# apt-get install ucspi-tcp

Launch tcpserver manually

This is the basic syntax. Use manpages for more information.

# tcpserver -q -H -R <PORT> <COMMAND/PROGRAM/SCRIPT>

-H       Do not look up the remote host name in DNS
-R       Do not attempt to obtain $TCPREMOTEINFO from the remote host

# tcpserver -H -R 3334 /root/SCRIPTS/

Test it

Lets execute a command through the tcp service…

# echo "/bin/ls /" | nc 3334
Command [/bin/ls /]

It works!


Leave a Reply

Your email address will not be published. Required fields are marked *