From owner-freebsd-questions@freebsd.org Fri Sep 15 00:55:04 2017 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6BA2BE18C94 for ; Fri, 15 Sep 2017 00:55:04 +0000 (UTC) (envelope-from luzar722@gmail.com) Received: from mail-it0-x232.google.com (mail-it0-x232.google.com [IPv6:2607:f8b0:4001:c0b::232]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 3218E71459 for ; Fri, 15 Sep 2017 00:55:04 +0000 (UTC) (envelope-from luzar722@gmail.com) Received: by mail-it0-x232.google.com with SMTP id z8so1639343itc.2 for ; Thu, 14 Sep 2017 17:55:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:date:from:user-agent:mime-version:to:subject :content-transfer-encoding; bh=DY9c8U8F1w9pEJOG2PY/SF2efwKf2LPg1j09KlEIZi4=; b=jCiBB8xVWlFvV1KQ2c1rt8pm7lSZ7xoFYRl/Zwu76DFOtic9kHulLJkzhQiR4K6Wmf wD6yy9HLIupCOUgdAQw48GC+job10DUFAcvv3cdWbvd1FiWVR/099rSRnv28gkV3GojY V0snWQ4M0wetdcEXD+QVzrWMJj/gEM1d9M6FgdNzb9KKXbxWRANhIspRHREYA96gw3A7 uPzsiSGjbUwpaq3Bk/TrxY22pTQIDIQV0KGadySxt2jM2f4FdXFXtqqgSUBZpV1rKnka Ff9eZCm8GsKmyOsA5XxrWoUlvzwhiAjwhA2q8/v6ElmYo5SNZHAmEHQZ/0aCFpOKIbXp tUOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :subject:content-transfer-encoding; bh=DY9c8U8F1w9pEJOG2PY/SF2efwKf2LPg1j09KlEIZi4=; b=jiH97c6tAOI2Too1j3DWFV9Lft1eYQEWBHBvX3+sNzw+kcmWZDK86925VusGSU4H4X qESgFWh+qq+4xGCW3J+wUr174Mwy/GHdJuqp/xJv4sGiNyfyokYVC39wzDo2NX3AJe+j 7PPaU2Ed0vcdv8PE29QSv0VYYj8VO8Kj3qBSmuGUj4PkgXD8RpamSNfdzqMQDgVETduC ACxLgG6NQuiFZLWLM87JXeVbSBDBOyiGPA9ULltwxnP/llh+GMThYhnx4sCESK03pmP6 hKCYQdKhT8VxTR1ot8q6UagxamVlFxfLbkXB4d4WgaXt4slKl5yW3btb8FBc6mXi0CcI FJAw== X-Gm-Message-State: AHPjjUjNFip/XjSxo3kYN4GBTKBN+YwAynFq2MZn4udDgdYNA4Pth4Kd Pz6UFwYRM3QxJUt/ X-Google-Smtp-Source: AOwi7QC7u1vGU9sDcW9jmyfSTUw6lXiOTMu5WUaI2fpQ0SqEPv6G19Lzpoolhy1lgWSe+U8bsN6gng== X-Received: by 10.36.238.6 with SMTP id b6mr3036252iti.113.1505436903195; Thu, 14 Sep 2017 17:55:03 -0700 (PDT) Received: from [10.0.10.3] (cpe-74-141-88-147.neo.res.rr.com. [74.141.88.147]) by smtp.googlemail.com with ESMTPSA id k18sm731108itb.2.2017.09.14.17.55.02 for (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 14 Sep 2017 17:55:02 -0700 (PDT) Message-ID: <59BB24E4.6060908@gmail.com> Date: Thu, 14 Sep 2017 20:55:00 -0400 From: Ernie Luzar User-Agent: Thunderbird 2.0.0.24 (Windows/20100228) MIME-Version: 1.0 To: "freebsd-questions@freebsd.org" Subject: Help scripting dns lookup using awk Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Sep 2017 00:55:04 -0000 The following sh script works, but runs very slow. host_in="$1" host_out="$2" host_error="$3" truncate -s 0 $host_out truncate -s 0 $host_error # Make the input file read a line at a time, not a field at a time. IFS=$'\n' set -f for line in `cat $host_in`; do domain_name=`echo -n $line | cut -w -f 1` host $domain_name > /dev/null if [ $? -ne 0 ]; then echo "$domain_name" >> $host_error else echo "$domain_name" >> $host_out fi done The follow script uses awk trying to do the same thing. host_in="$1" host_out="$2" host_error="$3" truncate -s 0 $host_out truncate -s 0 $host_error cat $host_in | awk ' { system(host $1) rc_status = system($0) if (rc_status != 0) print $1 > $host_error else print $1 > $host_out }' # command line exec command. >hosts2void-dns_lookup.awk /tmp/aw.hosts \ /root/good.dns /root/bad.dns # This is the output. sh: medrx.sensis.com.au: not found sh: medrx.sensis.com.au: not found awk: illegal field $(), name "host_error" input record number 1, file source line number 5 I see 2 problems with my awk code. 1. The text output of the host command results is going the console screen. In the sh version I kill the output using > /dev/null How would I to do something like that in awk. 2. I get that doing print $1 > $host_error is not allowed. What is the correct way to pass script variables to awk? Now I am wondering if there is a simpler way to do dns lookup in awk?