跨机器跟踪 pid (ssh)
我基本上是在尝试编写一个类似 pstree 的命令,只不过它应该遵循跨机器的进程。
我的意思是,如果我运行这个:
$ ssh $node sleep 1000
那么命令应该显示类似这样的内容:
ssh $node -- ($node) sleep 1000
如果我正在运行:
$ ssh $node ssh $node sleep 1000
ssh $node---($node) ssh $node---($node) sleep 1000
等等...
我的问题是:如何将一台机器上的一个 ssh 会话映射到生成的机器上在另一台机器上处理?
本地父子进程不是问题,但如何找出一个节点上的哪个 ssh 命令触发了另一个节点上的另一个进程。
linux 2.6.18
仅 openSSH 用于“远程”功能。当前正在运行 OpenSSH_4.3p2。
当然可以通过 SSH 访问所有节点(基于密钥的身份验证),因此所有节点都可以使用 ps 和 netstat。
仅限 Linux 的“黑客”很好,不需要可移植,尽管这当然会是一个额外的好处。
仅限 Linux 的“黑客”很好,不需要可移植,尽管这会是一个额外的好处用户将始终相同,并且我的命令/脚本以该用户身份运行。该用户不是 root。
不一定要快,只要准确。
自发的解决方案是编写一个 pstree
克隆,它在命令字符串“ssh
”上触发,找出源端口,然后转到有问题的远程计算机并找出 sshd 的哪个子级是由该特定命令生成的。
但也许有更聪明的方法? :P
I am basically trying to write a pstree-like command except that it should follow processes across machines.
What I mean is that if I run this :
$ ssh $node sleep 1000
Then the command should display something like this :
ssh $node -- ($node) sleep 1000
And if I'm running :
$ ssh $node ssh $node sleep 1000
ssh $node---($node) ssh $node---($node) sleep 1000
And so on ...
My question is this : How can I map one ssh session on one machine to a spawned process on another machine ?
Local parent-child processes are not a problem, but how can I figure out which ssh command on one node that triggered another process on another node.
linux 2.6.18
only openSSH for "remote" stuff. Running OpenSSH_4.3p2 currently.
SSH access to all nodes of course (key based auth) so ps and netstat are available from all nodes.
Linux-only "hacks" are fine, does not need to be portable though that would be an added bonus of course.
The user will always be the same and my command/script is running as that user. That user is not root.
Does not have to be fast, only accurate.
The spontaneous solution would be to write a pstree
clone, that triggers on the command string "ssh
", figures out the source-port and then goes to the remote machine in question and figures out which one of sshd
's children that was spawned by this particular command.
But maybe there's a more clever way ? :P
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上,我认为您自发的解决方案是正确的方法:使用 netstat 获取源端口并在远程计算机上查找它。如果不是 root,您可能会遇到使用“netstat -p”的问题 - 我在两台机器上尝试过,其中一台很乐意向我展示我自己的进程,而另一台则不然。
除了 ssh 客户端之外,您还可以扩展它来查找使用 ssh 连接的其他客户端,例如 rsync 或 Mercurial。只是要小心,不要递归地跟踪程序自己的连接!
使用 netstat 和 pstree 进行的快速实验表明这个想法是合理的:
我有兴趣查看结果,因为它对我非常有用!
Actually, I think your spontaneous solution is the right way to do it: use netstat to get the source-port and look for it on the remote machine. You might have trouble using "netstat -p" without being root - I tried it on two machines, one which was happy to show me my own processes and one which wasn't.
As well as ssh clients, you might extend this to look for other clients that use ssh connections, like rsync or Mercurial. Just be careful not to trace your program's own connection recursively!
A quick experiment with netstat and pstree shows that the idea is sound:
I'd be interested to see the result, because it would be very useful to me!