Reputation: 13
i run ( host ) command on a list of subdomain's to get the ip for each domain ... i want to ignore the not found: 3(NXDOMAIN) result i try with
for i in $(cat no-http.txt) ; do host $i 2>/dev/null; done
output :
e1792.dscx.akamaiedge.net has address 104.79.236.53
e1792.dscx.akamaiedge.net has IPv6 address 2a02:26f0:fa00:597::700
e1792.dscx.akamaiedge.net has IPv6 address 2a02:26f0:fa00:5a3::700
akamai-apigateway-warp3pl.tesla.com is an alias for akamai-apigateway-warp3pl.tesla.com.edgekey.net.
akamai-apigateway-warp3pl.tesla.com.edgekey.net is an alias for e1792.dscx.akamaiedge.net.
e1792.dscx.akamaiedge.net has address 104.79.236.53
e1792.dscx.akamaiedge.net has IPv6 address 2a02:26f0:fa00:5a3::700
e1792.dscx.akamaiedge.net has IPv6 address 2a02:26f0:fa00:597::700
Host olt.tesla.com not found: 3(NXDOMAIN)
^CHost kamai-apigateway-warp3pl.tesla.com not found: 3(NXDOMAIN)
Host kamai-apigateway-warpdashboardapi.tesla.com not found: 3(NXDOMAIN)
how i can redirect not found: replay to /dev/null
Upvotes: 0
Views: 136
Reputation: 19655
The NOT found causes host
to return 1 so test its return code.
#!/usr/bin/env sh
while read -r name; do
if reply=$(host "$name"); then
printf '%s\n' "$reply"
fi
done <no-http.txt
Upvotes: 2
Reputation: 782130
The "not found" message isn't being written to stderr, so you can't filter it by redirecting.
You can use grep -v
to filter it out.
for i in $(cat no-http.txt) ; do host "$i" ; done | grep -v 'not found'
Upvotes: 1