Can't see echo output of shell script using xinetd

416 Views Asked by At

I've created a simple shell script named /usr/sbin/helloworld

#!/bin/bash
echo "Hello World"
mkdir ~/itran
read -p "Say Hello : " hello
echo "$hello"
exit 0

I created /etc/xinetd.d/testservice-map as below

service testservice
{
    port            = 4079
    socket_type     = stream
    protocol        = tcp
    wait            = no
    user            = root
    server          = /usr/sbin/helloworld
    server_args     = test
}

and added the line below in /etc/services

testservice 4079/tcp

I've assigned one IP to my host and added an IPTABLE rule to redirect the request on port 22 of that IP to port 4079 of localhost

Now when I SSH to that IP using putty from another machine, from the logs (/var/log/messages) I can see that my service is being executed on the host but I can't see the "Hello World" message. The directory "itran" gets created but I can't see the echo message nor can I input any value.

I'm new to this. Kindly let me know if any more information is needed. Any help would be much appreciated.

1

There are 1 best solutions below

2
On

The problem that you have is that ssh does a lot more than you expect.

What happens is:

  • you start ssh
  • your ssh client sends an initiation of the session
  • your script launches and sends "Hello world"
  • your ssh client expects a server public key, but gets the hello world
  • You ssh-client terminates

With some verbose-options on your ssh-client, you can probably observe this behaviour.

Now, other clients do not have a first protocol handshake. If you have a telnet-client, you will probably get your expected result with

telnet 127.0.0.1 4079

Otherwise, try nc.