Last active
June 23, 2016 11:53
-
-
Save Cediddi/68b0fc8f725b9199a65a8d9b5a22d94b to your computer and use it in GitHub Desktop.
Sometimes you might want to use pdsh but you want the output to be ordered by server names. You can pipe this after the pdsh and it'll take care of the output. (shout out to @kalaomer for helping)
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
#!/usr/bin/env python | |
from sys import stdin | |
text = stdin.read() | |
from collections import defaultdict | |
ordered_output = defaultdict(list) | |
for line in text.split('\n'): | |
server_name = line[:line.find(':')] | |
server_output = line[line.find(':')+2:] | |
ordered_output[server_name].append(server_output) | |
sorted_keys = sorted(filter(bool, ordered_output.keys())) | |
for key in sorted_keys: | |
for value in ordered_output[key]: | |
print("{key}: {value}".format(key=key, value=value)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment