Posts

Showing posts from December, 2022

Warn yourself when your linux server isn't restarted for a while after an update (Python)

 You can see the python code below. It's suitable for RHEL/Centos/OEL servers: import subprocess import datetime import sys output = subprocess.check_output(["rpm","-qa","kernel-uek*"]) output = output.decode().strip().split("\n") output.sort(key=lambda x: subprocess.check_output(["rpm","-q","--queryformat","%{INSTALLTIME}",x])) output.reverse() active_kernel=subprocess.check_output(["uname","-r"]).decode().strip() active_kernel="kernel-uek-"+active_kernel #print(active_kernel) #print(output[0]) if active_kernel == output[0]:     print("Aktif kernel en güncel sürümdedir.")     sys.exit(0) else:     most_recent_install_date = subprocess.check_output(["rpm","-q", "--queryformat","%{INSTALLTIME}",output[0]])     most_recent_install_date = datetime.datetime.fromtimestamp(int(most_recent_install_date))     active_install_date = s