Created
December 10, 2020 02:37
-
-
Save haniawni/99ee6a57f3153faa186808569ddd890a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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