SHARE
TWEET

Untitled

a guest Jul 21st, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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]))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top