Sample Header Ad - 728x90

read files directly VS getent

9 votes
2 answers
2450 views
In various shell scripts I often see two approaches for getting information from databases supported by *Name Service Switch* libraries like /etc/group, /etc/hosts or /etc/services. One is getent utility and other is grep or some other text processing tool. For example: root@fw-test:~# getent passwd root root:x:0:0:root:/root:/bin/bash root@fw-test:~# root@fw-test:~# grep root /etc/passwd root:x:0:0:root:/root:/bin/bash root@fw-test:~# ..or: root@fw-test:~# getent hosts www.blah.com 189.113.174.199 www.blah.com root@fw-test:~# root@fw-test:~# host www.blah.com www.blah.com has address 189.113.174.199 root@fw-test:~# Which of those two approaches above should be used in scripts? I mean is one of the solutions more elegant or standard than the other?
Asked by Martin (8156 rep)
Apr 17, 2015, 12:29 PM
Last activity: Nov 28, 2018, 12:53 PM