-1

我在测试文件中有一个主机列表。我正在尝试将输出组织成 3 列。我想对主机名和 ilo-hostname 进行 nslookup 并将结果放入如下列中。

Hostname    IP-hostname ilo-hosntame
Host-1           FQN        FQN 
Host-2           FQN           ** server can't find Host-2: SERVFAIL

编辑:我现在有一个看起来像这样的文件

Hostname
IloHostname
Hotname
IloHostname
Hostname** server can't find IloHostname: SERVFAIL //当 Ilohostname 未找到或不存在时

用于创建此文件的脚本

egrep 'Name:|SERVFAIL' list3 | awk '{sub(/Name:/,"")}; 1' | awk '{$1=$1}1' | awk -F. '{print $1}'

list3 是 nslookup 的输出

4

2 回答 2

0
 This perl code maybe could be useful with some modifications:

#!/usr/bin/perl
use strict;
use warnings;
while(<DATA>){
    my %table;
    print;
    my @res = qx/nslookup $_/;
    my @eres = grep {/(\w+)\:\s+(\S+)\s*/g} @res;
    #now you got it
    foreach my $r (@eres){
        if ($r =~ /Name:(.*)/) {print "$1\t"}
        if ($r =~ /Address:(.*)\n/ and not $r =~ /\#/) {print "$1\n"}
    }
}

__DATA__
www.cisco.com
www.google.com
www.yahoo.com
于 2012-08-29T15:32:41.373 回答
0

You might use host instead of nslookup. It's output format is a little more amenable to post-processing to accomplish what you want.

于 2012-08-29T14:08:25.230 回答