Created
May 29, 2022 11:44
-
-
Save vaknin/a1e6f184e15c64559f119132e7decda6 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
NEW_USER_BORDER = "____________________________________________________________________________________________________" | |
# Read the log file | |
with open("log.txt") as f: | |
users = f.read() | |
final = '' | |
active_users = 0 | |
# Enumerate all users | |
users = users.split(NEW_USER_BORDER)[1:] | |
for user in users: | |
# Divide each user per fields | |
fields = list(filter(lambda txt: txt and "eltaweb.bat" not in txt and "Built-in" not in txt, user.splitlines())) | |
# Check whether the user is active | |
is_active = fields[4][29] == "Y" | |
# Increment the active users counter | |
if is_active: | |
active_users += 1 | |
# Only active users should be listed | |
else: | |
continue | |
# Fetch the username | |
username = fields[1][29:] | |
# Groups | |
groups = [] | |
fields = fields[10:] | |
for line in fields: | |
# Split by '*' | |
groups += list(map(lambda txt: txt[0: txt.find(" ")], line.split('*')[1:])) | |
# Add the '*' back and remove spaces | |
groups = list(map(lambda x: '*' + x.replace(' ', ''), groups)) | |
# Build the final string | |
final += f"User:{username}|Groups:{''.join(groups)}\n\n" | |
final = f'Total users: {len(users)}\nTotal active users: {active_users}\n\n' + NEW_USER_BORDER + '\n\n\n' + final[:-2] | |
# Read the log file | |
with open("log_new_format.txt", 'w') as f: | |
f.write(final) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment