Run command on all hosts in known_hosts file


/ Published in: Bash
Save to your folder(s)

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

Works better when [**auth.sh**](http://snipplr.com/view/46699/authsh/ "auth.sh") has been run on each host first.


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.