execresult("/usr/bin/..." /> execresult("/usr/bin/..." /> execresult("/usr/bin/..."/>

How to check current user with cfengine

98 views Asked by At

We are just started with cfengine and want to use the current logged in username of Ubuntu in our scripts.

"cur_user" string => execresult("/usr/bin/id -un","noshell")

This returns the current user. But as you now cfengine runs in the background as root which results in always the same answer and that's root.

Is their a predefined thing or is their something you guys now?

Kr,

Joeri

1

There are 1 answers

0
ASCIInaut On

As you already wrote /usr/bin/id always returns the id of the user which is running the current process. So using this command in Cfengine always returns the user root (as long as Cfengine is running as root).

If you want to get a list of all currently logged in users you might want to try the command /usr/bin/who. However this is not Cfengine specific and you need to process the output. You should keep in mind, that using Linux or UNIX, there can be more than one user logged in at the same time.