LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 10-07-2022, 04:45 PM   #1
arfon
Member
 
Registered: Apr 2004
Distribution: Slackware & RHEL
Posts: 367

Rep: Reputation: Disabled
Anyone know how to get inetd to create a file when a new connection is made?


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-
Code:
 myservice 5555/tcp
/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:
Code:
myservice 5555/tcp
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)

Last edited by arfon; 10-08-2022 at 01:08 AM. Reason: Added the solution
 
Old 10-07-2022, 05:59 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,670

Rep: Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892
Why are you still using inetd versus xinetd?
I have not played with inetd in many many years but the fields are defined as
Quote:
service-name
socket-type
protocol[,sndbuf=size][,rcvbuf=size]
wait|nowait[:max]
user[:group]
server-program
server program arguments
I would not expect you could actually execute a command as posted but then again I have never tried.
I would create a bash script to accept input from stdin and write to file. Something like:
Code:
#!/bin/bash
while IFS= read -r line; do
 echo "$line" >> /root/test.txt
done
If you save the script to /root then use.

Code:
myservice stream tcp nowait root /root/script.sh
Make sure you restart inetd.

Last edited by michaelk; 10-07-2022 at 06:38 PM.
 
1 members found this post helpful.
Old 10-07-2022, 11:01 PM   #3
arfon
Member
 
Registered: Apr 2004
Distribution: Slackware & RHEL
Posts: 367

Original Poster
Rep: Reputation: Disabled
"Why are you still using inetd versus xinetd?"
I'm running vanilla Slackware.

Unfortunately, the script.sh solution didn't work. It's still not making a file.

UPDATE: MichaelK, your solution IS working... For some reason inetd isn't liking the command I'm using on the other computer to send the data:

Code:
exec 3<>/dev/tcp/machine1/5555; echo -ne "some data" >&3

Last edited by arfon; 10-08-2022 at 01:08 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Made CSR request but cannot find the public.key that is made bscho Fedora 6 12-01-2020 07:57 PM
Inetd listening but no connection (ftp/Telnet) wowy Linux - Newbie 2 03-19-2015 05:35 AM
Does anyone know how to create an ".img" file for floppy/usb? linus72 Linux - Newbie 5 03-24-2009 07:17 PM
How do I determine which servers in Slack 11 are monitored by inetd / inetd.conf Old_Fogie Slackware 2 11-25-2006 01:06 PM
chrooting or jailing inetd or inetd started daemons ? MasterC Linux - Security 2 07-15-2003 05:28 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 12:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration