From 6947bb4f8c4df2e6d69bf65dde1fd91dd4a853e5 Mon Sep 17 00:00:00 2001 From: Stefan Weijers Date: Sun, 25 Jul 2021 16:00:30 +0200 Subject: [PATCH] Created services file --- diskusage.py | 3 +-- services.py | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 services.py diff --git a/diskusage.py b/diskusage.py index 39cc6c4..3854296 100644 --- a/diskusage.py +++ b/diskusage.py @@ -15,11 +15,10 @@ def generateBar(percentage): bar = bar + bcolors.UNUSED + '='*(barWidth - no_used) return bar + bcolors.RESET + ']' -mountpoints = ['/', '/dev'] cmd = 'df -h ' # Generate command to be executed -for mount in mountpoints: +for mount in env.mountpoints: cmd = cmd + mount + ' ' du = os.popen(cmd).read() # Execute command on system diff --git a/services.py b/services.py new file mode 100644 index 0000000..e7dabd9 --- /dev/null +++ b/services.py @@ -0,0 +1,23 @@ +import os +from config import bcolors,env + +def genLine(name, status, time): + if status == 'active': return '[' + name + '] [' + bcolors.EMPTY + '✓' + bcolors.RESET + '] [' + bcolors.EMPTY + time + bcolors.RESET + ']' + if status == 'inactive': return '[' + name + '] [' + bcolors.FULL + '✓' + bcolors.RESET + '] [' + bcolors.FULL + 'N/A' + bcolors.RESET + ']' + +statuscmd = 'systemctl is-active {}' +timecmd = 'systemctl status {} | grep -Po \".*; \K(.*)(?= ago)\"' + +statuslist = {} +timelist = {} + +srv = env.services.keys() + +for s in srv: + statuslist.update({s : os.popen(statuscmd.format(s)).read()}) + timelist.update({s : os.popen(timecmd.format(s)).read()}) + +print("Services running:") + +for s in srv: + print(genLine(env.services[s], statuslist[s].strip('\n'), timelist[s].strip('\n')))