diff --git a/__pycache__/ipLookup.cpython-34.pyc b/__pycache__/ipLookup.cpython-34.pyc new file mode 100644 index 0000000..d1b7db8 Binary files /dev/null and b/__pycache__/ipLookup.cpython-34.pyc differ diff --git a/__pycache__/uptime.cpython-34.pyc b/__pycache__/uptime.cpython-34.pyc new file mode 100644 index 0000000..53deb4e Binary files /dev/null and b/__pycache__/uptime.cpython-34.pyc differ diff --git a/testUptime.py b/testUptime.py new file mode 100755 index 0000000..b307fa9 --- /dev/null +++ b/testUptime.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# @Author: KevinMidboe +# @Date: 2016-11-22 16:08:17 +# @Last Modified by: KevinMidboe +# @Last Modified time: 2016-11-22 17:07:52 + +import uptime + +if __name__ == '__main__': + uptimeClass = uptime.uptime() + print(uptimeClass) \ No newline at end of file diff --git a/uptime.py b/uptime.py new file mode 100644 index 0000000..3c4c0c5 --- /dev/null +++ b/uptime.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# @Author: KevinMidboe +# @Date: 2016-11-22 16:05:18 +# @Last Modified by: KevinMidboe +# @Last Modified time: 2016-11-22 17:07:41 + +import subprocess, re + +class uptime(object): + """docstring for uptime""" + def __init__(self): + super(uptime, self).__init__() + raw = subprocess.Popen('uptime', stdout=subprocess.PIPE) + output, error = raw.communicate() + uptimeList = output.decode('utf-8').split(', ') + + self.duration(uptimeList[0]) + self.users(uptimeList[2]) + self.load(uptimeList[3]) + + def duration(self, outputString): + self.duration = re.sub(r'.*up ', '', outputString) + + def users(self, outputString): + self.users = outputString + + def load(self, outputString): + loadValues = re.sub(r'.*load averages: ', '', outputString) + self.load = re.sub(r'\n', '', loadValues) + self.load_minute, self.load_fiveminute, self.load_fiftenminute = self.load.split(' ') + + def __str__(self): + return str(self.__class__) + ": " + str(self.__dict__) \ No newline at end of file