korn shell

korn shell

Post by cheri » Fri, 12 May 2000 04:00:00



I'm writing a korn script and need to read in a list of ip
addresses and hostnames.  Any ideas how I can do this?

Thanks

* Sent from AltaVista http://www.altavista.com Where you can also find related Web Pages, Images, Audios, Videos, News, and Shopping.  Smart is Beautiful

 
 
 

korn shell

Post by Kenneth C Stah » Fri, 12 May 2000 04:00:00



> I'm writing a korn script and need to read in a list of ip
> addresses and hostnames.  Any ideas how I can do this?

> Thanks

> * Sent from AltaVista http://www.altavista.com Where you can also find related Web Pages, Images, Audios, Videos, News, and Shopping.  Smart is Beautiful

#!/bin/ksh
#the following line contains a tab character (Ascii 9) between the
#single quotes
typeset -r Tab='        ';
typeset -r Space=' ';
typeset -r Ifile='/etc/hosts';
typeset -L1 Col1='';
typeset -L25 Ip='';
typeset -L25 Host='';

exec 3<"${Ifile}";
if [[ $? -ne 0 ]];then
    print -u2 "Unable to open ${Ifile}";
    exit 1;
fi
IFS="${Space}${Tab}";
while read -u3 Ip Host Junk;do
    Col1="${Ip}";
    if [[ "${Col1}" = "#" ]];then
        continue;
    fi
    print -u1 "Host: ${Host} IP: ${Ip}";
done
exec 3<&-
exit 0;

 
 
 

korn shell

Post by Michael Sternber » Fri, 12 May 2000 04:00:00



> I'm writing a korn script and need to read in a list of ip
> addresses and hostnames.  Any ideas how I can do this?

    awk '!/^#/ && /./' | while read ip host rest
    do
        echo $ip $host
    done

Feed with /etc/hosts

Regards,
--
Michael Sternberg                        | Uni-GH Paderborn
http://www.phys.uni-paderborn.de/~stern/ | FB6 Theoretische Physik
phone: +49-(0)5251-60-2329   fax: -3435  | 33098 Paderborn, Germany
"Who disturrrbs me at this time?"  << Zaphod Beeblebrox IV >>     <*>