Posted By

cruelfate on 02/15/12


Tagged

Bash ssh


Versions (?)

Run command on all hosts in known_hosts file


 / Published in: Bash
 

Perform command on all hosts found in ~/.ssh/known_hosts

Works better when auth.sh has been run on each host first.

  1. #! /bin/bash
  2.  
  3. if [ $# -eq 0 ] ; then
  4. echo usage: $0 command
  5. exit 1
  6. fi
  7.  
  8. for h in $(cat ~/.ssh/known_hosts | cut -f 1 -d ' ' | cut -f 1 -d , | sort )
  9. do
  10. ping -q -o $h > /dev/null && echo -n "$h: " && ssh $h $*
  11. done

Report this snippet  

You need to login to post a comment.