Skip to main content
Tweeted twitter.com/#!/StackUnix/status/519609064548859904
added 11 characters in body
Source Link
deephacks
  • 625
  • 1
  • 5
  • 6

I want to execute an arbitrary command on multiple remote hosts using ssh. These commands are mostly long running commands that monitor server resources and aggregate the output to my local workstation (like tail -f, mpstat or tcpdump/tcpflow with grep etc) that monitor server resources and aggregate the output to my local workstation.

The problem is that I haven't found a way that keep the command running while later reliably terminating both the SSH connection and the remote command for all hosts.

I've tried many ssh flag variations, wait, cat, read, traps etc... Either both are killed instantly, the local terminal gets stuck or the remote command keeps running on the remote hosts after ssh connection was killed.

This is what I have at the moment.

function server_ssh() {
  pids=""
  for box in 01 02 03; do
    ssh -t -t -f server$box "$1" &
    pids="$pids $!"
  done
  trap 'kill -9 $pids' SIGINT
  # wait, cat, read ??
}

I want to execute an arbitrary command on multiple remote hosts using ssh. These commands are mostly long running commands (like tail -f or tcpdump/tcpflow with grep etc) that monitor server resources and aggregate the output to my local workstation.

The problem is that I haven't found a way that keep the command running while later reliably terminating both the SSH connection and the remote command for all hosts.

I've tried many ssh flag variations, wait, cat, read, traps etc... Either both are killed instantly, the local terminal gets stuck or the remote command keeps running on the remote hosts after ssh connection was killed.

This is what I have at the moment.

function server_ssh() {
  pids=""
  for box in 01 02 03; do
    ssh -t -t -f server$box "$1" &
    pids="$pids $!"
  done
  trap 'kill -9 $pids' SIGINT
  # wait, cat, read ??
}

I want to execute an arbitrary command on multiple remote hosts using ssh. These commands are mostly long running commands that monitor server resources and aggregate the output to my local workstation (like tail -f, mpstat or tcpdump/tcpflow with grep etc).

The problem is that I haven't found a way that keep the command running while later reliably terminating both the SSH connection and the remote command for all hosts.

I've tried many ssh flag variations, wait, cat, read, traps etc... Either both are killed instantly, the local terminal gets stuck or the remote command keeps running on the remote hosts after ssh connection was killed.

This is what I have at the moment.

function server_ssh() {
  pids=""
  for box in 01 02 03; do
    ssh -t -t -f server$box "$1" &
    pids="$pids $!"
  done
  trap 'kill -9 $pids' SIGINT
  # wait, cat, read ??
}
deleted 55 characters in body
Source Link
slm
  • 380.1k
  • 127
  • 793
  • 897

I want to execute an arbitrary command on multiple remote hosts using ssh. These commands are mostly long running commands (like tail -ftail -f or tcpdumptcpdump/tcpflowtcpflow with grepgrep etc) that monitor server resources and aggregate the output to my local workstation.

The problem is that I haven't found a way that keep the command running while later reliably terminating both the both the sshSSH connection and the remote command for all hosts.

I haveI've tried many sshssh flag variations, wait, cat, read, traps etc... Either both are killed instantly, the local terminal getgets stuck or the remote command keeps running on the remote hosts after ssh connection was killed.

This is what I have at the moment.

function server_ssh() {
  pids=""
  for box in 01 02 03; do
    ssh -t -t -f server$box "$1" &
    pids="$pids $!"
  done
  trap 'kill -9 $pids' SIGINT
  # wait, cat, read ??
}

Thankful for any help.

Cheers,
-Kristoffer

I want to execute an arbitrary command on multiple remote hosts using ssh. These commands are mostly long running commands (like tail -f or tcpdump/tcpflow with grep etc) that monitor server resources and aggregate the output to my local workstation.

The problem is that I haven't found a way that keep the command running while later reliably terminating both the both the ssh connection and the remote command for all hosts.

I have tried many ssh flag variations, wait, cat, read, traps etc... Either both are killed instantly, the local terminal get stuck or the remote command keeps running on the remote hosts after ssh connection was killed.

This is what I have at the moment.

function server_ssh() {
  pids=""
  for box in 01 02 03; do
    ssh -t -t -f server$box "$1" &
    pids="$pids $!"
  done
  trap 'kill -9 $pids' SIGINT
  # wait, cat, read ??
}

Thankful for any help.

Cheers,
-Kristoffer

I want to execute an arbitrary command on multiple remote hosts using ssh. These commands are mostly long running commands (like tail -f or tcpdump/tcpflow with grep etc) that monitor server resources and aggregate the output to my local workstation.

The problem is that I haven't found a way that keep the command running while later reliably terminating both the SSH connection and the remote command for all hosts.

I've tried many ssh flag variations, wait, cat, read, traps etc... Either both are killed instantly, the local terminal gets stuck or the remote command keeps running on the remote hosts after ssh connection was killed.

This is what I have at the moment.

function server_ssh() {
  pids=""
  for box in 01 02 03; do
    ssh -t -t -f server$box "$1" &
    pids="$pids $!"
  done
  trap 'kill -9 $pids' SIGINT
  # wait, cat, read ??
}
Source Link
deephacks
  • 625
  • 1
  • 5
  • 6

Cleanup trap for ssh command on multiple remote hosts

I want to execute an arbitrary command on multiple remote hosts using ssh. These commands are mostly long running commands (like tail -f or tcpdump/tcpflow with grep etc) that monitor server resources and aggregate the output to my local workstation.

The problem is that I haven't found a way that keep the command running while later reliably terminating both the both the ssh connection and the remote command for all hosts.

I have tried many ssh flag variations, wait, cat, read, traps etc... Either both are killed instantly, the local terminal get stuck or the remote command keeps running on the remote hosts after ssh connection was killed.

This is what I have at the moment.

function server_ssh() {
  pids=""
  for box in 01 02 03; do
    ssh -t -t -f server$box "$1" &
    pids="$pids $!"
  done
  trap 'kill -9 $pids' SIGINT
  # wait, cat, read ??
}

Thankful for any help.

Cheers,
-Kristoffer