Follow the pids through the machines (ssh)

I basically try to write the pstree-like command, except that it should follow the processes on the machines.

I mean, if I run this:

$ ssh $node sleep 1000

Then the command should display something like this:

ssh $node -- ($node) sleep 1000

And if I run:

$ ssh $node ssh $node sleep 1000

ssh $node---($node) ssh $node---($node) sleep 1000

Etc...

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 determine which ssh command on one node caused another process on another node.

  • linux 2.6.18

  • only openSSH for "remote". Running OpenSSH_4.3p2 now.

  • SSH access to all nodes of course (based on auth keys), so ps and netstat are accessible from all nodes.

  • Linux- "" , , , , .

  • , / script . root.

  • , .

pstree, "ssh", , sshd , .

, ?: P

+5
1

, , - : netstat, . "netstat -p" root - , , - .

ssh-, , , ssh-, rsync Mercurial. , .

netstat pstree , :

me@mymachine:~$ netstat -p
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 mymachine.example:43681 remote.example.com:ssh ESTABLISHED 27044/ssh
tcp        0      0 mymachine.example:39228 remote.example.com:ssh ESTABLISHED 14499/ssh
tcp        0      0 mymachine.example:45814 remote.example.com:ssh ESTABLISHED 20899/ssh
 me@mymachine:~$ ssh remote netstat -p | grep mymachine.example:43681
tcp        0      0 remote.example.com:ssh mymachine.example:43681 ESTABLISHED 10361/1
me@mymachine:~$ ssh remote pstree -a 10361
sshd
  `-grep -n -e wotsit -i -R /local/home/me/somewhere /dev/null

, !

+1

All Articles