Skip to content

Instantly share code, notes, and snippets.

@toddlers
Last active December 18, 2015 21:39
Show Gist options
  • Save toddlers/5849293 to your computer and use it in GitHub Desktop.
Save toddlers/5849293 to your computer and use it in GitHub Desktop.
passwd file parsing
# On a system the /etc/passwd has entries with duplicate uids, can you write a python program to print
# the users with duplicate uids.
# User x,y,z duplicate uid 10001 on line 4,7,8
# User x,x duplicate uid 10001 on line 4,10
# This is the initial need to update this
#!/usr/bin/ruby
require 'pp'
z = {}
File.open("passwd","r").each do |line|
lsp = line.chop.split(":",4)
z[lsp[0]] ||=0
z[lsp[2]] ||=0
z[lsp[0]] = z[lsp[0]] + 1
z[lsp[2]] = z[lsp[2]] + 1
end
z.each_key do |m|
if z[m] >= 2
puts "#{m} occurred #{z[m]} times"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment