You cannot receive the message inside your bash script, because there simply is no stream to receive on stdin
.
Using UDP, you are sending datagrams
which are handled differently by xinetd.
Receiving TCP Streams:
xinetd establishes a connection with your source host and forks an instance of your given script.
The stdin
(standard input) get's connected to stream of the source host. Then you can read
the input or do whatever you would do with a locally initiated run of your sendmail
process.
By the way: The stdout
get's connected to your source hosts stdin
as well and you can see answers or other messages, if you need bidirectional communication.
Receiving UDP Datagrams:
xinetd receives a datagram on your port and runs your script before even reading what it received. The (still unconnected) socket will be handed over to your script.
You need to do the full handling of reading datagrams by yourself, which is not as trivial as reading and writing streams. Also, this usually needs something more than a simple bash script.
(See recvfrom
and sendto
if you are interested in doing this)
From my perspective I'd recommend you to just switch over to a TCP stream for this. This will also ensure that your commands will actually reach your host or throw an exception on your source host for futher handling.
Edit: This is how your xinetd service would look like:
service test
{
socket_type = stream
protocol = tcp
port = 65534
user = root
server = /root/sendmail
}