Last Updated: February 25, 2016
·
442
· dwijnand

Check something on multiple remote hosts

I recently had to push out a change to the command-line flags of a auto-scaling service. When I rolled out the change it created 6 instances, so instead of manually ssh'ing into each box to run some combination of ps and grep I found a better solution: pssh, inline hosts list & pgrep.

The end result was:

pssh -P -O StrictHostKeyChecking=no $(service-hosts --az uk --env live --service that-service) pgrep -f Europe/London

where:

  • pssh is the parallel ssh
  • -P prints the output, in this case the pid of the found process
  • -O StrictHostKeyChecking=no disables ssh fingerprint checking, necessary as these were brand new boxes I'd never ssh'ed into before
  • service-hosts.. is my way to get the IPs of the instances in the auto-scaling group for the specified parameters, which output something like -H 10.0.0.2 -H 10.0.0.3 ...
  • pgrep is grep for processes
  • -f matches the whole command, instead of just its name
  • Europe/London is what I was checking ;)