tags:

views:

227

answers:

2

Let's say I have a list of ip's coming into a log that i'm tailing

1.1.1.1
1.1.1.2
1.1.1.3

etc..

and i'd like to easily resolve them to host names. I'd like to be able to

tail -f access.log | host -

Which fails as host doesn't understand input from stdin in this way. What's the easiest way to do with without having to write a static file or fall back to perl/python/etc.. ?

+7  A: 

Use xargs:

tail -f access.log | xargs host
Sinan Taifour
This will actually hiccup as host will actually be run with host 1.1.1.1 1.1.1.2Causing a dns lookup on an invalid DNS server. Setting "-d '\n'" doesn't seem to help it any.
tomasz
Use "xargs -l" (or "xargs -L 1") to ensure that the command is run for each line.
Jukka Matilainen
+2  A: 

You could also use the read builtin:

tail -f access.log | while read line; do host $line; done
Jukka Matilainen