You are not logged in.
Pages: 1
Server s1 listens on port 8888 and can accept connections from multiple device clients. It forwards data received on port 8888 to ports 9999, 9998, and 9997 on servers b1, b2, and b3, respectively. b1 can communicate bidirectionally with the device clients, while b2 and b3 can only receive data. I tried to use socat, but socat can't support run SYSTEM after fork TCP:
socat TCP-LISTEN:8888,fork TCP:b1:9999,reuseaddr \
SYSTEM:"tee >(socat - TCP:b2:9998) | \
socat - TCP:b3:9997 &how to fixed the command above? or any other command solution?
Thanks
Offline
Offline
thank you,
but your example is single direct to multi-address, I tried command like:
socat tcp4-listen:8888 - | tee >(socat - tcp4:127.0.0.1:9999) >(socat - tcp4:127.0.0.1:9998) > /dev/nullclient A:
socat readline tcp:localhost:8888device b1
socat tcp-l:9999device b2
socat tcp-l:99981. when A send message:
cmd1:hello
b1&b2 show message:
cmd1:hello
is OK
2. when b1 send message:
cmd2: hello from b1
A do not show any thing.
what's wrong ?
Offline
I tried this command:
#!/bin/bash
socat TCP-LISTEN:8888,fork TCP:localhost:9999,reuseaddr \
SYSTEM:"tee >(socat - TCP:localhost:9998) | \
socat - TCP:localhost:9997 | socat - TCP:localhost:9996" &but socat looks like not support fork TCP:xxx & SYSTEM in one command.
Offline
It works like this (requires bash as /bin/sh due to non-posix >() redirections)
socat tcp4-listen:8888,reuseaddr,fork system:'tee -p >(socat stdin tcp4:127.0.0.1:9997 >/dev/null) >(socat stdin tcp4:127.0.0.1:9998 >/dev/null) | socat - "tcp4:127.0.0.1:9999"'for each new connection socat (dispatcher) spawns a shell with tee that copies the data to two extra socats and then forwards it to the primary socat. That primary socat has its stdout connect to the dispatching socat and that sends it to your client
| alias CUTF='LANG=en_XX.UTF-8@POSIX ' | alias ENGLISH='LANG=C.UTF-8 ' |
Offline
It works like this (requires bash as /bin/sh due to non-posix >() redirections)
socat tcp4-listen:8888,reuseaddr,fork system:'tee -p >(socat stdin tcp4:127.0.0.1:9997 >/dev/null) >(socat stdin tcp4:127.0.0.1:9998 >/dev/null) | socat - "tcp4:127.0.0.1:9999"'for each new connection socat (dispatcher) spawns a shell with tee that copies the data to two extra socats and then forwards it to the primary socat. That primary socat has its stdout connect to the dispatching socat and that sends it to your client
<greatwall terminal1>$ cat so5
#!/bin/sh
socat tcp4-listen:8888,reuseaddr,fork system:"tee -p >(socat stdin tcp4:127.0.0.1:9997 >/dev/null) >(socat stdin tcp4:127.0.0.1:9998 >/dev/null) | socat - 'tcp4:127.0.0.1:9999'"<greatwall terminal1>$ ./so5
sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `tee -p >(socat stdin tcp4:127.0.0.1:9997 >/dev/null) >(socat stdin tcp4:127.0.0.1:9998 >/dev/null) | socat - tcp4:127.0.0.1:9999'<greatwall terminal2>$ socat readline tcp:localhost:8888looks like something wrong, :-(
Last edited by mygod100 (2023-04-22 12:55:02)
Offline
Are you really running that on archlinux or did you maybe change /bin/sh to another shell like dash? As I said, this requires bash as /bin/sh for process substitutions.
Last edited by progandy (2023-04-22 14:00:49)
| alias CUTF='LANG=en_XX.UTF-8@POSIX ' | alias ENGLISH='LANG=C.UTF-8 ' |
Offline
Are you really running that on archlinux or did you maybe change /bin/sh to another shell like dash? As I said, this requires bash as /bin/sh for process substitutions.
I tried /bin/bash, /bin/dash, /bin/zsh like this in so5 line one:
<greatwall terminal1>$ cat ./so5
#!/bin/dash
socat tcp4-listen:8888,reuseaddr,fork system:"tee -p >(socat stdin tcp4:127.0.0.1:9997 >/dev/null) >(socat stdin tcp4:127.0.0.1:9998 >/dev/null) | socat - 'tcp4:127.0.0.1:9999'"error always like this:
<greatwall terminal1>$ ./so5
sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `tee -p >(socat stdin tcp4:127.0.0.1:9997 >/dev/null) >(socat stdin tcp4:127.0.0.1:9998 >/dev/null) | socat - tcp4:127.0.0.1:9999'Offline
Are you really running that on archlinux or did you maybe change /bin/sh to another shell like dash? As I said, this requires bash as /bin/sh for process substitutions.
special bash version required?
Offline
type sh
stat /bin/shOffline
type sh stat /bin/sh
<greatwall terminal1>$ type sh
sh is hashed (/bin/sh)
<greatwall terminal1>$ stat /bin/sh
File: "/bin/sh" -> "bash"
Size: 4 Blocks: 0 IO Block: 4096 symbolic link
Device: fd00h/64768d Inode: 3977 Links: 1
Access: (0777/lrwxrwxrwx) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2023-04-28 09:38:01.580161765 +0800
Modify: 2012-07-26 19:29:19.207999981 +0800
Change: 2012-07-26 19:29:19.208999981 +0800Offline
Not "#!/bin/sh" or "#!/bin/dash" - this has to be "#!/bin/bash" like in #4 - did you actually try that?
Offline
Strange that. Does this work?
/bin/sh -c 'cat <(echo process subsitution works)'You can explicitly use bash like this:
socat tcp4-listen:8888,reuseaddr,fork exec:"/bin/bash /tmp/proxyscript.sh"and the contents of /tmp/proxyscript.sh
#!/bin/bash
tee -p >(socat stdin tcp4:127.0.0.1:9997 >/dev/null) >(socat stdin tcp4:127.0.0.1:9998 >/dev/null) | exec socat - 'tcp4:127.0.0.1:9999'| alias CUTF='LANG=en_XX.UTF-8@POSIX ' | alias ENGLISH='LANG=C.UTF-8 ' |
Offline
Strange that. Does this work?
/bin/sh -c 'cat <(echo process subsitution works)'You can explicitly use bash like this:
socat tcp4-listen:8888,reuseaddr,fork exec:"/bin/bash /tmp/proxyscript.sh"and the contents of /tmp/proxyscript.sh
#!/bin/bash tee -p >(socat stdin tcp4:127.0.0.1:9997 >/dev/null) >(socat stdin tcp4:127.0.0.1:9998 >/dev/null) | exec socat - 'tcp4:127.0.0.1:9999'
/bin/sh -c 'cat <(echo process subsitution works)'show :
/bin/sh: -c: line 0: syntax error near unexpected token `('
/bin/sh: -c: line 0: `cat <(echo process subsitution works)'but
/bin/bash -c 'cat <(echo process subsitution works)'show :
process subsitution workslooks like works well.
so I use command:
/bin/bash -c 'socat -v TCP-LISTEN:8888,reuseaddr,fork exec:"./proxyscript.sh"', it works.
in #4 and any other script file I use:
#!/bin/bashin first line, but looks like not work,I don't know why?
Last edited by mygod100 (2023-05-01 09:04:08)
Offline
Not "#!/bin/sh" or "#!/bin/dash" - this has to be "#!/bin/bash" like in #4 - did you actually try that?
yes, as #14, I don't know why it "#!/bin/bash" in first line of scipt not works
Offline
progandy wrote:Strange that. Does this work?
/bin/sh -c 'cat <(echo process subsitution works)'You can explicitly use bash like this:
socat tcp4-listen:8888,reuseaddr,fork exec:"/bin/bash /tmp/proxyscript.sh"and the contents of /tmp/proxyscript.sh
#!/bin/bash tee -p >(socat stdin tcp4:127.0.0.1:9997 >/dev/null) >(socat stdin tcp4:127.0.0.1:9998 >/dev/null) | exec socat - 'tcp4:127.0.0.1:9999'/bin/sh -c 'cat <(echo process subsitution works)'show :
/bin/sh: -c: line 0: syntax error near unexpected token `(' /bin/sh: -c: line 0: `cat <(echo process subsitution works)'but
/bin/bash -c 'cat <(echo process subsitution works)'show :
process subsitution workslooks like works well.
so I use command:
/bin/bash -c 'socat -v TCP-LISTEN:8888,reuseaddr,fork exec:"./proxyscript.sh"', it works.
in #4 and any other script file I use:
#!/bin/bashin first line, but looks like not work,I don't know why?
an other question, I use like this to listen port 9997, same like 9998,9999:
socat tcp-l:9997 -if the port not on listening before run proxyscript.sh or restart after shutdown port listening, the forwarding will broken and can not auto re-establish, is there any way to auto re-establish?
Offline
Please avoid full-quotes to keep the thread reasonably scrollable.
yes, as #14, I don't know why it "#!/bin/bash" in first line of scipt not works
How exactly do you invoke the script (when testing it or otherwise)
Do you just run it or do you "sh /path/to/script"?
Offline
There is a difference between running the outer socat with bash and using system for the children and using exec with bash for the children. system will always run /bin/sh.
| alias CUTF='LANG=en_XX.UTF-8@POSIX ' | alias ENGLISH='LANG=C.UTF-8 ' |
Offline
The posix mode also doesn't seem to affect the substitution behavior (ie. " /bin/sh -c 'cat <(echo process subsitution works)'" works fine here)
xterm -e /bin/sh
# in the xterm
cat <(echo process subsitution works)
stat /proc/$$/exe
shopt -oq posix && echo posixThen try the same w/
xterm -e /bin/sh --norcOffline
Pages: 1