0

I manage a running program by sending a command-character through telnet. I usually do it step by step:

telnet localhost 12345
command-character
ctrl+]
quit

Is it possible that I send the command-character from bash directly, or if not, write a bash script to do that?

fiedel
  • 31
  • 6
  • `printf '%s' "$char" >/dev/tcp/localhost/12345` – Charles Duffy May 21 '20 at 15:32
  • Thanks @CharlesDuffy My program prompted receiving a sigPipe signal. This seems to be raised by the underlying system. – fiedel May 21 '20 at 18:01
  • Means you're writing to a closed FIFO. – Charles Duffy May 21 '20 at 18:47
  • Could this be caused by my program? It did respond to telnet service requests normally. – fiedel May 21 '20 at 20:12
  • Whatever is on the other side of the FIFO you're writing to is the thing responsible for closing that end as-and-when it chooses to do so. If you need detailed control, btw, I would use `socat` instead of either `/dev/tcp` *or* `netcat`... but that should already be covered in the linked duplicate. – Charles Duffy May 21 '20 at 20:34

1 Answers1

1

Do you need to use telnet? I would use the netcat (nc)

Anyway the related thread: https://unix.stackexchange.com/a/160597

so for example:

echo 'c' | nc localhost 12345

for 'c' use any other character

pstanko
  • 11
  • 2
  • 1
    Answers need to be complete enough to stand alone even if links they contain break. "I would use netcat" doesn't tell someone *how* to use netcat. – Charles Duffy May 21 '20 at 15:33
  • ok thank you, edited. That is why I have provided the link th the related thread. – pstanko May 21 '20 at 15:37
  • Thank you @pstanko. With this command my program received the character, but it stays with the telnet session and didn't exit. – fiedel May 21 '20 at 18:02