Skip to content

Instantly share code, notes, and snippets.

@bast
Last active July 25, 2016 23:18
Show Gist options
  • Save bast/cd838766745703cc30564f9d75b7ba7e to your computer and use it in GitHub Desktop.
Save bast/cd838766745703cc30564f9d75b7ba7e to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
"""
Example for user 'someuser':
$ rocks run host compute 'python /home/user/find-undead.py someuser' | grep -v down | grep -v untrusted
"""
def run_command(command):
import subprocess
import shlex
import re
process = subprocess.Popen(shlex.split(command),
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
return stdout
def main():
import sys
username = sys.argv[-1]
top = run_command('ps -u {0}'.format(username))
num_lines = len(top.split('\n'))
if num_lines > 1:
print(run_command('hostname'))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment