Code Comments
Programming Forum and web based access to our favorite programming groups.Hi all!
I am working on a project in which there's something to be done with
which I need a little help: a file containing lines with ip-addresses
which should be replaced by the hostname of the servers instead of the
ip-addresses.
I tried several ways, without succes. Most close I came with a "for i"
statement
and a AWK {print $5} construction. However, I need some directives to
complete the job of the conversion from the ip-address to the
hostname. what do I use?
nslookup, dig, hostname?
I assumed something like this:
hosts=/tmp/temprep0
for ip in $hosts ; do
if [ ".$host" = 10.65. ] ; then
for i in `netstat -in | awk
'{if(substr($1,1,1)!="N")print$1}' | sed 's/\*//g'` ; do
ifconfig $i
done
continue
fi
sed 's/$/ /' < /etc/hosts > $tmp2 || die "sed failed"
grep -i "[ ]$host[ ]" $tmp2 > $tmp
if [ $? = 0 ] ; then
head -1 $tmp | awk '{printf("%-30s %s\n",$2,$1)}'
else
if [ -r /etc/resolv.conf ] ; then
nslookup $host 2>&1 | sed 's/[ ]*,[ ]*/ /' >
$tmp
fgrep '***' $tmp > /dev/null
if [ $? = 0 ] ; then
echo "$prog: host '$host' not found" 1>&2
continue
fi
Anyone?
Thanx in advance
Post Follow-up to this messageIn article <cnklp8$28u$1@aken.eed.ericsson.se>, Michael Tosch wrote:
> In article <717da987.0411190122.48d918e7@posting.google.com>, bvweelde@che
llo.nl (Bas) writes:
>
> Sorry, I dont understand what your script does and what it should do
> instead. An example would be helpful.
>
> Is it just about IP-to-host translation?
> Then this works best:
>
> getent hosts $ip | awk '{print $2}'
That assumes you have 'getent', which on my HP-UX boxes I do not...
Kevin
Post Follow-up to this messageIn article <cnklp8$28u$1@aken.eed.ericsson.se>, Michael Tosch wrote:
> In article <717da987.0411190122.48d918e7@posting.google.com>, bvweelde@che
llo.nl (Bas) writes:
>
> Sorry, I dont understand what your script does and what it should do
> instead. An example would be helpful.
>
> Is it just about IP-to-host translation?
> Then this works best:
>
> getent hosts $ip | awk '{print $2}'
That assumes you have 'getent', which on my HP-UX boxes I do not...
Kevin
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.