Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 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]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement