Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import csv
- FILENAME = "users.csv"
- all_data = []
- users = []
- systems = []
- try:
- etc_pass = open("/etc/passwd", "r").read()[:-1]
- except IOError:
- exit()
- for line in etc_pass.split('\n'):
- uid = int(line.split(':')[2])
- username = line.split(':')[0]
- if uid > 999 and uid < 65534 :
- users.append(username)
- else:
- systems.append(username)
- try:
- group_all = open("/etc/group", "r").read()[:-1]
- except IOError:
- exit()
- for user in users:
- collect_groups = []
- for i in group_all.split('\n'):
- group_name = i.split(':')[0]
- group_user = i.split(':')[3]
- if user in group_user:
- collect_groups.append(group_name)
- collect_list = []
- collect_list.append(user)
- collect_list.append(collect_groups)
- all_data.append(collect_list)
- with open(FILENAME, "w") as file:
- for i in all_data:
- writer = csv.writer(file)
- writer.writerow(i)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement