Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pipe text from port 2222 to script using xinetd

Status
Not open for further replies.

geebers

Technical User
May 29, 2009
20
US
i have xinetd setup to run myscript.sh whenever some text is sent to port 2222.
but i'm needing to pipe the text into myscript.sh

example:
- client sends string "11111" to server port 2222
- myscript.sh is executed with "11111" as the first argument.

can this be done?
thanks for any help.
 
What you are describing is not "piping" the text to myscript.sh, but passing it as a parameter.

In fact, xinetd's default behaviour is to "pipe" the input to the script it calls through standard input. This is a better way anyway, because the input isn't limited to a single line or a limited number of characters.

You can access the standard input using a loop such as:

Code:
while read INPUT
do
    echo "received data was: $INPUT"
    # or if you wish to call a script with the input as a parameter:
    /path/to/some/other/script.sh "$INPUT"
done

Annihilannic.
 
I tried your suggestion, did not seem to work.

if myscript.sh contains this....
#!/bin/sh
echo "test" >newfile.txt

and I run...
sudo nc -u 192.168.1.100 2222
"type some text and hit enter"

then it works. a new file called "newfile.txt" is created which contains the string "text".

However, this does not work....
#!/bin/sh
while read INPUT; do
echo "$INPUT" >newfile.txt
done

no file is created.

any clues? Here's the contents of my /etc/xinetd.d/myscript

service myscript
{
port = 2222
socket_type = dgram
protocol = udp
wait = yes
user = fred
server = /home/fred/myscript.sh
log_on_success += USERID
log_on_failure += USERID
disable = no
}

thanks for any help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top