Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [17:33:01] [8.8] root@ded457:~/python# cat blahzaantu.py
- #!/usr/bin/python3.4
- import mysql.connector
- import time
- import subprocess
- import getopt
- import sys
- import mysql.connector
- import time
- import re
- import os
- from subprocess import check_output
- def main():
- outfile = "/var/log/blah2.log"
- loadlimit = float(0)
- try:
- opts, args = getopt.getopt(sys.argv[1:], "ho:l:v", ["help", "outfile=", "load="])
- except getopt.GetoptError as err:
- print (str(err))
- usage()
- sys.exit(2)
- for o, a in opts:
- if o == '-v':
- verbose = True
- elif o in ("-h", "--help"):
- usage()
- sys.exit()
- elif o in ("-o", "--outfile"):
- outfile = a
- elif o in ("-l", "--loadlimit"):
- loadlimit = a
- else:
- assert False, "bip boop error with args"
- cnx = mysql.connector.connect(user='root', password='mbREGGYjEeiA', host='localhost')
- cursor = cnx.cursor()
- if os.path.exists(outfile):
- append_write = 'a' # append if already exists
- else:
- append_write = 'w' # make a new file if not
- result_file = open(outfile, append_write)
- p = re.compile("load average: ([0-9]*[.][0-9]+)")
- while True:
- cursor.execute("show full processlist")
- processlist = cursor.fetchall()
- uptime = check_output(["uptime"])
- time.sleep(1);
- #ldresult = p.search(uptime.decode('ascii'))
- ldresult = p.search(uptime.decode('ascii'))
- if(float(ldresult.group(1)) >= loadlimit):
- result_file.write(str(processlist))
- result_file.write('\n')
- result_file.write(str(uptime))
- result_file.write('\n')
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement