3 # Closely (not perfectly) emulate the behavior of glibc's getent utility
5 #passwd|shadow|group|aliases|hosts|networks|ethers|netgroup|protocols|services|rpc
6 # only returns the first match (by design)
7 # dns based search is not supported (hosts,networks)
8 # case-insensitive matches not supported (ethers; others?)
9 # may return false-positives (hosts,protocols,rpc,services,ethers)
11 [ -z "$PATH" ] && PATH
="/bin:/usr/bin" || PATH
="${PATH}:/bin:/usr/bin"
17 match
="^$2:\|^[^:]*:[^:]*:$2:" ;;
21 match
="^[[:space:]]*$2\>" ;;
22 hosts|protocols|rpc|services|ethers
)
25 match
="^[[:space:]]*$2[[:space:]]*:" ;;
27 echo "USAGE: $0 database [key]"
30 echo "$0: Unknown database: $1" 1>&2
34 if [ ! -f "$file" ] ; then
35 echo "$0: Could not find database file for $1" 1>&2
39 if [ $# -eq 1 ] ; then
42 sed "s/#.*//; /$match/q; d" "$file" |
grep . ||
exit 2