|
|
@ -2,7 +2,12 @@ from jinja2 import Environment, FileSystemLoader
|
|
|
|
import subprocess
|
|
|
|
import subprocess
|
|
|
|
from datetime import datetime, timedelta
|
|
|
|
from datetime import datetime, timedelta
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
import fnmatch
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(sys.argv) > 1:
|
|
|
|
|
|
|
|
time_ag_arg = int(sys.argv[1])
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
time_ag_arg = False
|
|
|
|
|
|
|
|
|
|
|
|
#create the log directory
|
|
|
|
#create the log directory
|
|
|
|
path = "/home/xpub/www/html/tl-dr/log-books"
|
|
|
|
path = "/home/xpub/www/html/tl-dr/log-books"
|
|
|
@ -13,6 +18,12 @@ if not os.path.exists(path):
|
|
|
|
now = datetime.today()
|
|
|
|
now = datetime.today()
|
|
|
|
book_name = "TL;DR_" + now.strftime("%B %dth %Y")
|
|
|
|
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"]
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
return ["-S","today"]
|
|
|
|
|
|
|
|
|
|
|
|
def create_all_logs_file():
|
|
|
|
def create_all_logs_file():
|
|
|
|
list_logs = subprocess.run(["ls", "/home/xpub/www/html/tl-dr/log-books"], capture_output=True)
|
|
|
|
list_logs = subprocess.run(["ls", "/home/xpub/www/html/tl-dr/log-books"], capture_output=True)
|
|
|
|
|
|
|
|
|
|
|
@ -34,9 +45,11 @@ def run_command(command, based = False):
|
|
|
|
# Run all the commands for getting the logs, and assign to variables
|
|
|
|
# Run all the commands for getting the logs, and assign to variables
|
|
|
|
print("start running the log commands");
|
|
|
|
print("start running the log commands");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# journalctl --utc
|
|
|
|
last_user_added = subprocess.run(["sudo", "journalctl","_COMM=useradd","-r","-n", "1" , "--output-fields=MESSAGE"], capture_output=True)
|
|
|
|
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)
|
|
|
|
last_user_added_name = run_command(['grep', '-Po', "(?<=name)\W*\K[^ ]*"], based=last_user_added.stdout)
|
|
|
|
users_created_today = run_command(["sudo", "journalctl", "-S","today","_COMM=useradd","-r","--output-fields=MESSAGE"]).splitlines()
|
|
|
|
users_created_today = run_command(["sudo", "journalctl","_COMM=useradd","-r"] + get_journalctl_on()).splitlines()
|
|
|
|
|
|
|
|
|
|
|
|
since_last_boot = run_command(["uptime","-s"])
|
|
|
|
since_last_boot = run_command(["uptime","-s"])
|
|
|
|
slb_date = datetime.strptime(since_last_boot, "%Y-%m-%d %H:%M:%S")
|
|
|
|
slb_date = datetime.strptime(since_last_boot, "%Y-%m-%d %H:%M:%S")
|
|
|
@ -105,9 +118,9 @@ output = template.render(
|
|
|
|
|
|
|
|
|
|
|
|
print("Output the files");
|
|
|
|
print("Output the files");
|
|
|
|
# Export the html as book.html, which is used as an input for pandoc
|
|
|
|
# Export the html as book.html, which is used as an input for pandoc
|
|
|
|
with open("/home/xpub/www/html/tl-dr/book.html", "w") as f:
|
|
|
|
with open(f"/home/xpub/www/html/tl-dr/book_${time_ag_arg}.html", "w") as f:
|
|
|
|
print(output, file=f)
|
|
|
|
print(output, file=f)
|
|
|
|
subprocess.run(['sh', '/home/xpub/www/html/tl-dr/create_book.sh', book_name])
|
|
|
|
# subprocess.run(['sh', '/home/xpub/www/html/tl-dr/create_book.sh', book_name])
|
|
|
|
print("Finished");
|
|
|
|
print("Finished");
|
|
|
|
|
|
|
|
|
|
|
|
# At the moment, we are not storing logs in the log folder anymore
|
|
|
|
# At the moment, we are not storing logs in the log folder anymore
|
|
|
|