我需要捕获socat
在远程服务器上运行的详细和调试输出。
socat
在前台运行时我可以实现上述目标:
$ socat -x -d -d -d tcp-l:8080,bind=0.0.0.0,fork,reuseaddr - 2>stderr.log >stdout.log
但是,如果在后台运行上述内容,则不会收到任何输出stdout.log
nohup
:
$ nohup socat -x -d -d -d tcp-l:8080,bind=0.0.0.0,fork,reuseaddr - 2>stderr.log >stdout.log &
这是stderr.log
我启动nohup
socat
上面的版本后的情况:
nohup: ignoring input
2024/03/24 20:06:22 socat[28360] I socat by Gerhard Rieger and contributors - see www.dest-unreach.org
2024/03/24 20:06:22 socat[28360] I This product includes software developed by the OpenSSL Project for use in the OpenSSL Toolkit. (http://www.openssl.org/)
2024/03/24 20:06:22 socat[28360] I This product includes software written by Tim Hudson ([email protected])
2024/03/24 20:06:22 socat[28360] I setting option "bind" to "0.0.0.0"
2024/03/24 20:06:22 socat[28360] I setting option "fork" to 1
2024/03/24 20:06:22 socat[28360] I setting option "so-reuseaddr" to 1
2024/03/24 20:06:22 socat[28360] I socket(2, 1, 6) -> 5
2024/03/24 20:06:22 socat[28360] W ioctl(5, IOCTL_VM_SOCKETS_GET_LOCAL_CID, ...): Inappropriate ioctl for device
2024/03/24 20:06:22 socat[28360] I starting accept loop
2024/03/24 20:06:22 socat[28360] N listening on AF=2 0.0.0.0:8080
接下来我8080
从 netcat 连接到端口,
$ nc localhost 8080
这就是stderr.log
捕获的内容:
2024/03/24 20:06:59 socat[28360] I accept(5, {2, AF=2 127.0.0.1:37910}, 16) -> 6
2024/03/24 20:06:59 socat[28360] N accepting connection from AF=2 127.0.0.1:37910 on AF=2 127.0.0.1:8080
2024/03/24 20:06:59 socat[28360] I permitting connection from AF=2 127.0.0.1:37910
2024/03/24 20:06:59 socat[28360] N forked off child process 28563
2024/03/24 20:06:59 socat[28360] I close(6)
2024/03/24 20:06:59 socat[28360] I still listening
2024/03/24 20:06:59 socat[28360] N listening on AF=2 0.0.0.0:8080
2024/03/24 20:06:59 socat[28563] I just born: child process 28563
2024/03/24 20:06:59 socat[28563] I close(4)
2024/03/24 20:06:59 socat[28563] I close(3)
2024/03/24 20:06:59 socat[28563] I just born: child process 28563
2024/03/24 20:06:59 socat[28563] I close(5)
2024/03/24 20:06:59 socat[28563] N reading from and writing to stdio
2024/03/24 20:06:59 socat[28563] I resolved and opened all sock addresses
2024/03/24 20:06:59 socat[28563] N starting data transfer loop with FDs [6,6] and [0,1]
2024/03/24 20:06:59 socat[28563] E read(0, 0x60485184f000, 8192): Bad file descriptor
2024/03/24 20:06:59 socat[28563] N exit(1)
2024/03/24 20:06:59 socat[28563] I shutdown(6, 2)
2024/03/24 20:06:59 socat[28360] N childdied(): handling signal 17
2024/03/24 20:06:59 socat[28360] I childdied(signum=17)
2024/03/24 20:06:59 socat[28360] I childdied(17): cannot identify child 28563
2024/03/24 20:06:59 socat[28360] I waitpid(): child 28563 exited with status 1
2024/03/24 20:06:59 socat[28360] I waitpid(-1, {}, WNOHANG): No child processes
2024/03/24 20:06:59 socat[28360] I childdied() finished
接下来,我在 netcat 终端中输入一些文本,然后按 ENTER。
然而,问题是:不仅 netcat 退出,我stdout.log
也看不到我输入的文本。
除了阐明这里发生的情况之外,有人还可以建议如何捕获nohup
'ed的 stderr 和 stdoutsocat
吗?本质上,我需要捕获远程套接字客户端发送到的所有数据-v
和-d -d -d
输出。stderr.log
stdout.log