Skip to content

Instantly share code, notes, and snippets.

@haniawni
Created December 10, 2020 02:37
Show Gist options
  • Save haniawni/99ee6a57f3153faa186808569ddd890a to your computer and use it in GitHub Desktop.
Save haniawni/99ee6a57f3153faa186808569ddd890a to your computer and use it in GitHub Desktop.
import glob, subprocess
def run_command(command): # found this on stackoverflow
p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
return iter(p.stdout.readline, b'')
iFiles = glob.glob("/var/log/apt/history.log*")
iFiles.sort(reverse=True) # to get the files in date order but not really critical
for f in iFiles:
command = ['zcat', '-f', f]
for line in run_command(command):
if "Start-Date:" in line:
sp_ln = line.split(" ")
print sp_ln[1].strip(),
elif "Commandline:" in line:
sp_ln = line.partition(" ")
print sp_ln[2].strip()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment