Code:
nc -l -p 5555 > /root/test.txt
...receives connection/data fine but, I don't want nc running all of the time. I want inetd accept the connection and dump the message to a file.
I have tried:
/etc/services-
/etc/inetd.conf-
Code:
myservice stream tcp nowait root /bin/sh sh -c "cat > /root/test.txt"
and
Code:
myservice stream tcp nowait root /bin/sh sh -c "nc -l -p 5555 > /root/test.txt"
The 'sending machine' doesn't complain about "connection refused" so it looks like inetd is accepting the connection but, the files are not being created.
I even tried:
Code:
myservice stream tcp nowait root /bin/sh sh -c "touch /root/test.txt"
...and test.txt is not getting created.
UPDATE: Inetd doesn't like the commands above nor does it like command I'm using on the sending machine...
*** SOLUTION ***
MACHINE 1 /etc/services add:
Machine 1 /etc/inetd.conf add:
Code:
myservice stream tcp nowait root /root/tcpread.sh
Machine 1 create /root/tcpread.sh:
Code:
#!/bin/bash
while IFS= read -r line; do
echo "$line" >> /root/tcpout.txt
done
Machine 1:
Code:
chmod 755 /etc/rc.d/rc.inetd
/etc/rc.d/rc.inetd start
chmod 755 /root/tcpread.sh
Machine 2 (send a message):
Code:
echo -n 'Line of text' | nc machine1 5555
(TY MichaelK)