Commits

Travis Odom committed c3aedea Draft

Added ps output, handling for old dmesg

Comments (0)

Files changed (1)

 #!/usr/bin/python2
 
-import time, tempfile, paramiko, scp
-from subprocess import check_output
+import time, tempfile, paramiko, scp, subprocess
+from os import getenv
 
-def SendFile(filename):
+def SendFile(filenames):
     client = paramiko.SSHClient()
     client.load_system_host_keys()
     client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
-    client.connect('localhost')
+    client.connect('development.g33xnexus.com')
 
     scpCli = scp.SCPClient(client.get_transport())
-    scpCli.put(filename)
+    scpCli.put(filenames)
 
 last = ''
 outFile = tempfile.NamedTemporaryFile()
 while(True):
     output = []
-    current = check_output("dmesg -T | tail -20", shell=True).split("\n")
-    if current[19][1:24] > last:
+    current = subprocess.check_output("dmesg -T | tail -20", stderr=subprocess.STDOUT, shell=True)
+
+# handle old dmesg lacking the -T option
+    if current[:5] == "dmesg":
+        current = subprocess.check_output("dmesg | tail -20", stderr=subprocess.STDOUT, shell=True)
+    current = current.split("\n")
+
+    if current[19][1:12] > last:
         for line in current:
-            if line[1:24] > last:
+            if line[1:12] > last:
                 output.append(line)
-        last = current[19][1:24]
+        last = current[19][1:12]
+        stats = subprocess.check_output("ps aux --sort=-pcpu | head", shell=True).split("\n")
 
     print output, last
     if len(output) > 0:
         outFile.writelines("%s\n" % item for item in output)
         outFile.flush()
         print outFile.name
-        SendFile(outFile.name)
+        with open(getenv("HOME") + "/last-ps", "w") as psFile:
+            psFile.writelines("%s\n" % item for item in stats)
+            psFile.flush()
+            SendFile([outFile.name, psFile.name])
     time.sleep(10)