5

Part 1

Is getent supposed to be an executable?

In my zsh setup, I can see getent is actually defined as a function

$ which getent   
getent () {
    if [[ $2 = <-> ]]
    then
        grep ":$2:[^:]*$" /etc/$1
    else
        grep "^$2:" /etc/$1
    fi
}

If I want to execute it from bash shell,

bash -c  "getent passwd user"  

I get a getent: command not found error.

Part 2

In Mac OSX, getent fails regardless if the user id is valid or not. It turns out the user id is not kept in the /etc/passwd file. Why it is so? And what is the alternative?

Anthony Kong
  • 3,638

2 Answers2

6

On linux, Solaris and (I believe) *BSD systems getent is an executable and will consult the same set of databases as normal lookup functions (/etc files, LDAP, NIS etc).

Os-x doesn't provide getent but you can get similar functionality using the dscacheutil or dsutil programs (which talk to the directory services back end). A web search for "osx getent" will give you more details.

Paul Haldane
  • 4,612
-1

getent AND dsutil fail for me as well on OSX bash.

As Paul points out above, this command dscacheutil will work. I was able to get the specific user verified with this command:

dscacheutil -q user -a name <username>. 

A list of users with this command

dscacheutil -q user | grep 'name:'
Michael Hampton
  • 252,907