Python code for store system load into file and display stored system load

Python code for store system load into file

#!/usr/bin/python

import os
try:
    t = os.popen('uptime').read()[:-1]
    #print(t)
    f=open("/home/website/public_html/public/load.txt", "a+")
    f.write("%s\r\n" %t)
    f.close()
    f.flush()
except IOError as (errno,strerror):
    print "I/O error({0}): {1}".format(errno, strerror)

Python code for display system load stored into file

#!/usr/bin/python

import os
try:
    f = open("/home/website/public_html/public/load.txt", "r")
    print(f.read())
    f.close()
    f.flush()
except IOError as (errno,strerror):
    print "I/O error({0}): {1}".format(errno, strerror)


Leave a Reply