Created
November 8, 2020 21:10
-
-
Save spagu/7d762d972a649a0b7e2fdfb4056814c4 to your computer and use it in GitHub Desktop.
List vsftpd log entries that are 2 days old only (slow version)
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
#!/usr/bin/env python | |
import re | |
import datetime | |
format = '%b %d %H:%M:%S %Y' | |
filepath = '/var/log/vsftpd.log' | |
now = datetime.datetime.now() | |
now24 = now + datetime.timedelta(-2) | |
def parse_date_from_log_line(line): | |
t_pat = re.compile(r".*([A-Za-z]{3}\s+[0-9]{1,2}\s(?:\d|[01]\d|2[0-3])(:[0-5][0-9]){2}\s20([0-9]){2}).*?") | |
date_string = t_pat.search(line).group(1) | |
format = '%b %d %H:%M:%S %Y' | |
return datetime.datetime.strptime(date_string, format) | |
with open(filepath) as fp: | |
for cnt, line in enumerate(fp): | |
if ( parse_date_from_log_line(line) >= now24 ): | |
print( line ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment