Created
November 20, 2014 15:58
-
-
Save PaulReiber/cc234ee02c0845b4b7d1 to your computer and use it in GitHub Desktop.
Collect command outputs from all nodes in a cloud
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # | |
| # setup: to populate all-nodes file on a fuel master, run this once in a while: | |
| # fuel node|awk '/ready/ {print "node-" $1}'|sort >all-nodes | |
| # otherwise, put a list of hostnames on separate lines in all-nodes | |
| # | |
| # usage: | |
| # collect <args> | |
| # | |
| # runs <args> on all nodes, collecting output into a nicely named file in | |
| # a directory associated with each node. | |
| # | |
| ################################################################################ | |
| # construct a filename using the arguments but ensuring it can be a filename | |
| # it replaces slashes, spaces, redirects, and pipes, and adds the current date | |
| now="_"`date +%j_%T` | |
| filename=`echo $* $now|sed -e 's,/,_,g' -e 's/ //g' -e 's/>/_gt_/g' -e 's/</_lt_/g' -e 's/|/=/g'` | |
| # loop over all nodes ssh-ing to them, sourcing openrc, and running our arguments | |
| # output from the command goes into the filename whose name we created above, | |
| # in a directory for the node. | |
| for h in `cat all-nodes`; do \ | |
| [ -d $h ] || mkdir $h ; \ | |
| echo -n '.' && \ | |
| ssh -n $h '. openrc;'$* > $h/$filename 2<&1; done | |
| echo "done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment