user list

29 views
Skip to first unread message

thierry thunot

unread,
Jan 2, 2023, 5:36:27 AM1/2/23
to help-cfengine
Hello everyone, happy new year to all

I am facing a problem I am trying to filter my users and to establish a list of users whose UID is greater than 999.

i used getusers  but I feel like the function's uid filter doesn't apply....
i tried this solution :
"allusers" slist => getusers("","0"); to have uid 0 but there is no result

or
"allusers" slist => getusers("","[1-9]{1,3}");
 or
 have you got solution to extract all users whith UID greater than 999???

Thanks for your help

Nick Anderson

unread,
Jan 3, 2023, 5:40:39 PM1/3/23
to thierry thunot, help-c...@googlegroups.com

thierry thunot <tth...@gmail.com> writes:

I am facing a problem I am trying to filter my users and to establish a list of users whose UID is greater than 999.

i used getusers but I feel like the function's uid filter doesn't apply…. i tried this solution : "allusers" slist => getusers("","0"); to have uid 0 but there is no result

or "allusers" slist => getusers("","[1-9]{1,3}"); or have you got solution to extract all users whith UID greater than 999???

I think the documentation isn't very clear about it. The list is a string, specifically a comma separated string of uids to filter.

You can use expandrange() and join() to generate a comma separated string of ids from 0 to 999 being used as a filter:

bundle agent __main__
{
  vars:
    "users" slist => getusers( "", "");
    "users_id_gt_999" slist => getusers( "", join( ",", expandrange( "[0-999]", 1 ) ) );
}
[root@hub masterfiles]# cf-agent -KIf ./example.cf --show-evaluated-vars=default:main\\.
Variable name                            Variable value                                               Meta tags                                Comment
default:main.users                        {"root","bin","daemon","adm","lp","sync","shutdown","halt","mail","operator","games","ftp","nobody","systemd-network","dbus","polkitd","rpc","tss","rpcuser","nfsnobody","sshd","postfix","chrony","vagrant","cfapache","cfpostgres"} source=promise
default:main.users_id_gt_999              {"nfsnobody","vagrant"}                                     source=promise

– Nick Anderson | Doer of Things | (+1) 785-550-1767 | https://northern.tech

thierry thunot

unread,
Jan 4, 2023, 4:12:28 AM1/4/23
to help-cfengine
Thank you very much for your answer it's great

Nick Anderson

unread,
Jan 4, 2023, 12:59:23 PM1/4/23
to thierry thunot, help-c...@googlegroups.com

thierry thunot <tth...@gmail.com> writes:

Thank you very much for your answer it's great

Great, glad that you found it helpful.

I went ahead and updated the docs.

https://docs.cfengine.com/docs/3.21/reference-functions-getusers.html#top

And, hopefully my change to make our automatic arguments rendering for functions will be accepted so that more rich descriptions from cf-promises --syntax-description=json of each argument will be included as well.

https://tracker.mender.io/browse/CFE-4128

Reply all
Reply to author
Forward
0 new messages