#!/bin/sh hostsfile="/etc/hosts" syntax1="gethost: Get info from $hostsfile. Required parm 1 is search string." syntax2="Optional parm 2 is output type. If output type is NOT supplied," syntax3="the whole line from $hostsfile is returned but '-rtr' and '-pc' names" syntax4="are excluded. If output type IS supplied, only that type is returned." syntax5="Syntax: gethost {ip address | host name | mac address} {ip | name | mac}" if [ -z $1 ] # No parm 1 then echo echo $syntax1 echo $syntax2 echo $syntax3 echo $syntax4 echo echo $syntax5 echo exit fi if [ -z $2 ] # No parm 2 specified, so echo whole line, e.g. # 192.168.168.80 lattin 00:06:25:11:FC:A5 then ip_name_mac=$(grep $1 $hostsfile | grep -v "\-rtr" | grep -v "\-pc") output=$ip_name_mac else # Parm 2 was specified ip_name_mac=$(grep $1 $hostsfile) if [ $2 = "ip" ] then output=$(echo $ip_name_mac | cut --delim=" " --fields=1) elif [ $2 = "name" ] then output=$(echo $ip_name_mac | cut --delim=" " --fields=2) elif [ $2 = "mac" ] then output=$(echo $ip_name_mac | cut --delim=" " --fields=3) else # other/unknown output=$ip_name_mac fi fi echo $output exit