Last active
July 25, 2016 23:18
-
-
Save bast/cd838766745703cc30564f9d75b7ba7e to your computer and use it in GitHub Desktop.
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 | |
""" | |
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