Skip to content

Instantly share code, notes, and snippets.

@jumanjiman
Created February 8, 2013 13:44
Show Gist options
  • Save jumanjiman/4739111 to your computer and use it in GitHub Desktop.
Save jumanjiman/4739111 to your computer and use it in GitHub Desktop.
print conflicting user account info when nsswitch uses multiple sources, such as local and ldap
#!/usr/bin/env ruby
# vim: set ts=2 sw=2 ai et bg=dark:
class Record < Struct.new(:name, :uid, :gid, :dir)
end
records = Array.new
%x!getent passwd!.split("\n").each do |record|
fields = record.split(':')
records << Record.new(
fields[0], # name
fields[2], # uid
fields[3], # gid
fields[5] # homedir
)
end
users = Hash.new
records.each do |record|
if user = users[record.name]
user[:uids] << record.uid unless user[:uids].include?(record.uid)
user[:gids] << record.gid unless user[:gids].include?(record.gid)
user[:dirs] << record.dir unless user[:dirs].include?(record.dir)
else
users[record.name] = {
:uids => [record.uid],
:gids => [record.gid],
:dirs => [record.dir],
}
end
end
users.each do |name, hash|
puts "#{name} uids => #{hash[:uids].join(',')}" if hash[:uids].length > 1
puts "#{name} gids => #{hash[:gids].join(',')}" if hash[:gids].length > 1
puts "#{name} dirs => #{hash[:dirs].join(',')}" if hash[:dirs].length > 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment