Dynamically update user list
This commit is contained in:
parent
a3a835312c
commit
f751af45ef
4 changed files with 28 additions and 8 deletions
|
|
@ -1,2 +1,23 @@
|
|||
require 'open3'
|
||||
|
||||
module HomeHelper
|
||||
|
||||
def list_all_users
|
||||
stdout, stderr, status = Open3.capture3('getent', 'passwd')
|
||||
return [] unless status.success?
|
||||
valid_users = stdout.split("\n").select { |user| user.start_with?(/\w/) }.map(&:split).map(&:first)
|
||||
valid_users.map do |user|
|
||||
user.split(':')[0]
|
||||
end
|
||||
end
|
||||
|
||||
def users_with_public_html(users)
|
||||
users.select do |user|
|
||||
home_dir = Dir.home(user)
|
||||
File.exist?(File.join(home_dir, 'public_html'))
|
||||
end
|
||||
end
|
||||
|
||||
users = list_all_users
|
||||
users_with_public_html(users)
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue