Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. from collections import defaultdict
  4.  
  5. # Initialize dictionary of user ids
  6. uids = defaultdict(list)
  7.  
  8. # loop through password file, building dictionary of uid:[list of usernames]
  9. with open("/etc/passwd") as passwd_file:
  10. for line in passwd_file:
  11. line_array = line.split(":")
  12. uids[line_array[2]].append(line_array[0])
  13.  
  14. # loop though dictionary.
  15. # If duplicate usernames for uid found, print on standard out
  16.  
  17. for uid in uids:
  18. if len(uids[uid]) > 1:
  19. print ( uid + ": " + " ".join(uids[uid]))
  20. #!/usr/bin/env python
  21.  
  22. from collections import defaultdict
  23.  
  24. # Initialize dictionary of group ids
  25. gids = defaultdict(list)
  26.  
  27. # loop through password file, building dictionary of gid:[list of groups]
  28. with open("/etc/group") as group_file:
  29. for line in group_file:
  30. line_array = line.split(":")
  31. gids[line_array[2]].append(line_array[0])
  32.  
  33. # loop though dictionary.
  34. # If duplicate group for gid found, print on standard out
  35.  
  36. for gid in gids:
  37. if len(gids[gid]) > 1:
  38. print ( gid + ": " + " ".join(gids[gid]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement