Skip to content

Instantly share code, notes, and snippets.

@Cediddi
Last active June 23, 2016 11:53
Show Gist options
  • Save Cediddi/68b0fc8f725b9199a65a8d9b5a22d94b to your computer and use it in GitHub Desktop.
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)
#!/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