Shell Scripting: Read entries from administrative database

Posted on in Categories News last updated March 5, 2006

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 and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

1 comment

Leave a Comment