Shell Scripting: Read entries from administrative database

last updated in Categories News

While scripting it is necessary to gather entries from administrative database such as passwd, group files or services, protocols or networks etc. Traditionally grep is choice of all UNIX administrators but recently I found GNU getent command. The command is quick, saves time:

The getent program gathers entries from the specified administrative database using the specified search keys. For example:

$ getent passwd vivek
$ getnet group admins
$ getent protocols vrrp
$ getent services www

Overall, it supports following databases:

  • ahosts
  • ahostsv4
  • ahostsv6
  • aliases
  • ethers
  • group
  • hosts
  • netgroup
  • networks
  • passwd
  • protocols
  • rpc services
  • shadow

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

1 comment

    Have a question? Post it on our forum!