do not use some vars on timeago

main
vitrinekast 9 months ago
parent be6a862b7c
commit 00d78ed784

@ -5,9 +5,10 @@ import os
import sys
if len(sys.argv) > 1:
time_ag_arg = int(sys.argv[1])
time_ago_arg = int(sys.argv[1])
print(f"Going back in time by {time_ago_arg} days")
else:
time_ag_arg = False
time_ago_arg = False
#create the log directory
path = "/home/xpub/www/html/tl-dr/log-books"
@ -19,8 +20,8 @@ now = datetime.today()
book_name = "TL;DR_" + now.strftime("%B %dth %Y")
def get_journalctl_on():
if time_ag_arg:
return ["-S", f"{time_ag_arg + 1} days ago", "-U", f"{time_ag_arg} days ago"]
if time_ago_arg:
return ["-S", f"{time_ago_arg + 1} days ago", "-U", f"{time_ago_arg} days ago"]
else:
return ["-S","today"]
@ -45,33 +46,32 @@ def run_command(command, based = False):
# Run all the commands for getting the logs, and assign to variables
print("start running the log commands");
# These vars cannot go back in time
if not time_ago_arg:
since_last_boot = run_command(["uptime","-s"])
slb_date = datetime.strptime(since_last_boot, "%Y-%m-%d %H:%M:%S")
time_since_last_boot = now - slb_date
device_info_grab = subprocess.run(["grep", 'Model' , "/proc/cpuinfo"], check=True, capture_output=True)
device_info = run_command(['awk', '-F:', '{ print $2}'], based=device_info_grab.stdout)
ip_address_show = subprocess.run(["ip", "addr", "show", "end0"], check=True, capture_output=True)
ip_address = run_command(['awk', '$1 == "inet" {gsub(/\/.*$/, "", $2); print $2}' ], based=ip_address_show.stdout)
# journalctl --utc
last_user_added = subprocess.run(["sudo", "journalctl","_COMM=useradd","-r","-n", "1" , "--output-fields=MESSAGE"], capture_output=True)
last_user_added_name = run_command(['grep', '-Po', "(?<=name)\W*\K[^ ]*"], based=last_user_added.stdout)
users_created_today = run_command(["sudo", "journalctl","_COMM=useradd","-r"] + get_journalctl_on()).splitlines()
since_last_boot = run_command(["uptime","-s"])
slb_date = datetime.strptime(since_last_boot, "%Y-%m-%d %H:%M:%S")
time_since_last_boot = now - slb_date
dpkg_date = now.strftime("%Y-%m-%d")
list_package_installs = subprocess.run(["grep","-E", dpkg_date + '.*install|install.*' + dpkg_date, "/var/log/dpkg.log"], capture_output=True).stdout.decode('UTF-8').splitlines()
list_package_upgrade = subprocess.run(["grep","-E", dpkg_date + '.*upgrade|upgrade.*' + dpkg_date, "/var/log/dpkg.log"], capture_output=True).stdout.decode('UTF-8').splitlines()
list_package_remove = subprocess.run(["grep","-E", dpkg_date + '.*remove|remove.*' + dpkg_date, "/var/log/dpkg.log"], capture_output=True).stdout.decode('UTF-8').splitlines()
device_info_grab = subprocess.run(["grep", 'Model' , "/proc/cpuinfo"], check=True, capture_output=True)
device_info = run_command(['awk', '-F:', '{ print $2}'], based=device_info_grab.stdout)
ip_address_show = subprocess.run(["ip", "addr", "show", "end0"], check=True, capture_output=True)
ip_address = run_command(['awk', '$1 == "inet" {gsub(/\/.*$/, "", $2); print $2}' ], based=ip_address_show.stdout)
print("start running the service commands, this sometimes takes longer");
logins_today_log = subprocess.run(["sudo", "journalctl","_COMM=systemd-logind", "-S", "today", "-g", "New session" ], check=True, capture_output=True)
# journalctl --utc
last_user_added = subprocess.run(["sudo", "journalctl","_COMM=useradd","-r","-n", "1" , "--output-fields=MESSAGE"], capture_output=True)
last_user_added_name = run_command(['grep', '-Po', "(?<=name)\W*\K[^ ]*"], based=last_user_added.stdout)
users_created_today = run_command(["sudo", "journalctl","_COMM=useradd","-r"] + get_journalctl_on()).splitlines()
# TODO: merge into one command and then grep the various _COMM\s, wrap in a function
groupadd_today_log = subprocess.run(["sudo", "journalctl", "-S","today","_COMM=groupadd","-r"], check=True, capture_output=True)
@ -118,7 +118,7 @@ output = template.render(
print("Output the files");
# Export the html as book.html, which is used as an input for pandoc
with open(f"/home/xpub/www/html/tl-dr/book_${time_ag_arg}.html", "w") as f:
with open(f"/home/xpub/www/html/tl-dr/book_{time_ago_arg}.html", "w") as f:
print(output, file=f)
# subprocess.run(['sh', '/home/xpub/www/html/tl-dr/create_book.sh', book_name])
print("Finished");

Loading…
Cancel
Save