Skip to content

Commit

Permalink
Tested and fixed users_create.py script on ifarm
Browse files Browse the repository at this point in the history
  • Loading branch information
DraTeots committed Jun 30, 2024
1 parent 738a9a3 commit f020b91
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions scripts/users_create/users_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,20 @@ def get_names(groupid):
output = []

# Execute the 'getent group' command
proc = subprocess.Popen(['getent', 'group'], stdout=subprocess.PIPE, text=True)

# Read the output line by line
for line in proc.stdout:
if f':{groupid}:' in line:
group_count += 1
if group_count > 1:
output.append(',')
# Split the line and get the part after the group ID
parts = line.strip().split(f':{groupid}:')
if len(parts) > 1:
output.append(parts[1])
# we do str(int(groupid)) to be sure we are safe of wrong input type
proc = subprocess.Popen(['getent', 'group', str(int(groupid))], stdout=subprocess.PIPE, text=True)
output, _ = proc.communicate()

# The result will be something like halld:*:267:user1,user2,... so we split by ':'
members_str = output.strip().split(':')[-1].strip()

print(f"Parsing members list for GroupID={groupid}:")
print(members_str)

members = members_str.split(',')
# Join the output list into a single string and print
print(''.join(output))
return output
print(f"Total members of GroupID={groupid}: {len(members)}")
return members


def get_user_names_from_ypmatch(ypstr):
Expand Down Expand Up @@ -167,5 +165,5 @@ def main():


if __name__ == "__main__":
get_names()
#main()
main()

0 comments on commit f020b91

Please sign in to comment.