I use interactive
bash shell over TCP network, but can't figure out how to send CTRL+c sequence to the remote
I first run
netcat instance (this is where I interact with remote bash):
nc -nvlp 8000
Then, from the remote I run (for simplicity, I use localhost so you can try it out locally in another terminal):
bash -i >& /dev/tcp/localhost/8000 0>&1
Now, in the netcat terminal the interactive bash appeared and I can send commands to it, which get executed and the result is shown.
What I didn't figure out yet, is how to propagate CTRL+c sequence to the remote bash and ignore it within the
Here is what I've tried so far:
nc -nvlp 8000 & trap "printf '\003' >/proc/$!/fd/0" INT; fg; trap 0 INT
netcat in the background, sets up
trap, which prints end-of-file sequence (
0x03) to the stdin of the netcat if
SIGINT is received.
Then, using the
fg command, the
netcat process is brought to the foreground so that the interactive session can begin. Executing commands works just fine, but when I use CTRL+c sequence,
netcat dies with
130 return code, printing nothing in either the
netcat, nor the
The final trap resets the
bash process ends with
0 return code, indicating success.
Any ideas, how this could be done?