1832964 Members
2527 Online
110048 Solutions
New Discussion

Inetd script

 
SOLVED
Go to solution
Alex Lavrov
Regular Advisor

Inetd script

Hello!

I'm trying to write a script that uses inetd.
It works fine when it uses stdou and when I telnet it, I get all the output, but for some reason when I'm trying to send something to it (I use read command in the script), it just ignores it.
Are there any samples available how to do it?
7 REPLIES 7
Laurent Menase
Honored Contributor

Re: Inetd script

Hi Alex,

On my system when I do:

#!/usr/bin/ksh

while read a
do
echo "$a"
done

telnet to that service just echo what I type in
the telnet, so it should work for you too?
# telnet 127.0.0.1 32123
Trying...
Connected to 127.0.0.1.
Escape character is '^]'.
&é&é"é&
&é&é"é&
12345
12345

If there is no endofline charactere, you must use a=$(dd bs=1 count=1
Alex Lavrov
Regular Advisor

Re: Inetd script

Hello,
I tried it and I get
"Connection to host lost."
Laurent Menase
Honored Contributor
Solution

Re: Inetd script

is your file executable?
do you have anything in the syslog.log?
Cesare Salvioni
Trusted Contributor

Re: Inetd script

I think that problem is related to new line char which, in TCP connection, is always ^J^M while in unix is only ^J.
If the server started by inetd is a script try this command to get a line:

read line
line="$(echo $line|sed 's/^M//')"

this should get the line properly.
Hope this helps
Cesare Salvioni
Trusted Contributor

Re: Inetd script

forgot to say:
enter ^M with the characters CTRL-V CTRL-M
Cesare Salvioni
Trusted Contributor

Re: Inetd script

Little example script is attached
Here are the lines to add:

/etc/services:
myserv 950/tcp

/etc/inetd.conf:
myserv stream tcp nowait root /tmp/myserv myserv

save th attached script in /tmp/myserv, chmod it 555 and run inetd -c

check /var/adm/syslog/syslog.log, you should see something like new service added

try to telnet the host on port 950, it should ask u a file name, show i and ask again untill u answer END

hope this helps
Alex Lavrov
Regular Advisor

Re: Inetd script

Thanx for the help, I did exactly what you recommended, but I mistyped the path to my script and that was the problem ;)