Last active
December 18, 2015 21:39
-
-
Save toddlers/5849293 to your computer and use it in GitHub Desktop.
passwd file parsing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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