diff --git a/script.py b/script.py index d0d9005..9b1d647 100644 --- a/script.py +++ b/script.py @@ -90,13 +90,26 @@ journal_today = subprocess.run(["sudo", "journalctl","_COMM=systemd-logind","_CO kitchen_services = run_command(["sudo", "journalctl", "-u", "kitchen-stove.service", "-u", "kitchen-bin.service", "-u", "kitchen-fridge.service", "-r", "-n"] + get_journalctl_on()).splitlines() +try: + groups_created = subprocess.run(['grep','groupadd'], capture_output=True, input=journal_today.stdout)..stdout.decode('UTF-8').strip().splitlines() + groups_removed = subprocess.run(['grep','groupremove'], capture_output=True, input=journal_today.stdout)..stdout.decode('UTF-8').strip().splitlines() + users_created_today = subprocess.run(['grep','useradd'], capture_output=True, input=journal_today.stdout)..stdout.decode('UTF-8').strip().splitlines() + user_modified = subprocess.run(['grep','usermod'], capture_output=True, input=journal_today.stdout)..stdout.decode('UTF-8').strip().splitlines() + user_deleted = subprocess.run(['grep','userdel'], capture_output=True, input=journal_today.stdout)..stdout.decode('UTF-8').strip().splitlines() + logins_today = subprocess.run(['grep','New session'], capture_output=True, input=journal_today.stdout)..stdout.decode('UTF-8').strip().splitlines() + +except subprocess.CalledProcessError as e: + raise RuntimeError("command '{}' return with error (code {}): {}".format(e.cmd, e.returncode, e.output)) + + + # loading the jinja template environment print("Filling the template"); env = Environment(loader=FileSystemLoader("/home/xpub/www/html/tl-dr/templates")) # loading the template (use template.jinja when generating the html webview) template = env.get_template("book.jinja") -fallback = list_package_installs + # rendering the template and storing the resultant text in variable output output = template.render( now = now.strftime("%B %dth %Y"), @@ -113,12 +126,12 @@ output = template.render( list_active_services = run_command(["sudo", "service", "--status-all"]).splitlines() if not time_ago_arg else False, debian_version = run_command(["cat", "/etc/debian_version"]) if not time_ago_arg else False, hostname = run_command(["hostname","-i"]) if not time_ago_arg else False, - groups_created = run_command(['grep', '-v','groupadd'], based=journal_today.stdout).splitlines(), - groups_removed = run_command(['grep', '-v','groupremove'], based=journal_today.stdout).splitlines(), - users_created_today = run_command(['grep', '-v','useradd'], based=journal_today.stdout).splitlines(), - user_modified = run_command(['grep', '-v','usermod'], based=journal_today.stdout).splitlines(), - user_deleted = run_command(['grep', '-v','userdel'], based=journal_today.stdout).splitlines(), - logins_today = run_command(['grep', '-v','New session'], based=journal_today.stdout).splitlines(), + groups_created = groups_created, + groups_removed = groups_removed, + users_created_today = users_created_today, + user_modified = user_modified, + user_deleted = user_deleted, + logins_today = logins_today )