<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How can Splunk loop through a list of numbers and do an action against each of them? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-can-Splunk-loop-through-a-list-of-numbers-and-do-an-action/m-p/481625#M134976</link>
    <description>&lt;P&gt;TBH, this is probably easier to do with a bash script.&lt;/P&gt;</description>
    <pubDate>Tue, 03 Mar 2020 13:24:40 GMT</pubDate>
    <dc:creator>richgalloway</dc:creator>
    <dc:date>2020-03-03T13:24:40Z</dc:date>
    <item>
      <title>How can Splunk loop through a list of numbers and do an action against each of them?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-Splunk-loop-through-a-list-of-numbers-and-do-an-action/m-p/481624#M134975</link>
      <description>&lt;P&gt;We have got a problem to find a list of 500+ client servers (but less than 1000), which are missing DNS entries. the servers have a pattern luckily  . Let's say for example, the server names are  &lt;CODE&gt;myhost001&lt;/CODE&gt; to &lt;CODE&gt;myhost999&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;So we want to loop through all those servers and do a dnslookup&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|makeresults
| eval src_host_001="myhost001"
...
| eval src_host_999="myhost999"
| foreach src_host_* [eval src_host=&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;]
|lookup dnslookup clienthost as src_host OUTPUTNEW clientip
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Is there a way, we can loop using a pattern, so I don't want to use a lookup file or external csv?&lt;BR /&gt;
Ideally the logic I'm trying to replicate is &lt;BR /&gt;
for a range of  &lt;CODE&gt;myhost[0-9][0-9][0-9]&lt;/CODE&gt; , loop through each of them and do a &lt;CODE&gt;dnslookup&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;So something like in sort of&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;for id in $( seq 1 999 ); do {
    src_host=myhost${id}
   ##|lookup dnslookup clienthost as ${src_host} OUTPUTNEW clientip
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;thanks in advance&lt;/P&gt;</description>
      <pubDate>Tue, 03 Mar 2020 12:57:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-Splunk-loop-through-a-list-of-numbers-and-do-an-action/m-p/481624#M134975</guid>
      <dc:creator>koshyk</dc:creator>
      <dc:date>2020-03-03T12:57:04Z</dc:date>
    </item>
    <item>
      <title>Re: How can Splunk loop through a list of numbers and do an action against each of them?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-Splunk-loop-through-a-list-of-numbers-and-do-an-action/m-p/481625#M134976</link>
      <description>&lt;P&gt;TBH, this is probably easier to do with a bash script.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Mar 2020 13:24:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-Splunk-loop-through-a-list-of-numbers-and-do-an-action/m-p/481625#M134976</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2020-03-03T13:24:40Z</dc:date>
    </item>
    <item>
      <title>Re: How can Splunk loop through a list of numbers and do an action against each of them?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-Splunk-loop-through-a-list-of-numbers-and-do-an-action/m-p/481626#M134977</link>
      <description>&lt;P&gt;wished we had got access to backend &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;/P&gt;</description>
      <pubDate>Tue, 03 Mar 2020 13:55:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-Splunk-loop-through-a-list-of-numbers-and-do-an-action/m-p/481626#M134977</guid>
      <dc:creator>koshyk</dc:creator>
      <dc:date>2020-03-03T13:55:11Z</dc:date>
    </item>
    <item>
      <title>Re: How can Splunk loop through a list of numbers and do an action against each of them?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-Splunk-loop-through-a-list-of-numbers-and-do-an-action/m-p/481627#M134978</link>
      <description>&lt;P&gt;Hi @koshyk,&lt;/P&gt;

&lt;P&gt;Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=999 
| eval number = 1 
| streamstats sum(number) as number 
| eval src_host=case(len(number)==1, "myhost00".number, len(number)==2, "myhost0".number, 1==1, "myhost".number)
| lookup dnslookup clienthost as src_host OUTPUTNEW clientip
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Mar 2020 14:12:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-Splunk-loop-through-a-list-of-numbers-and-do-an-action/m-p/481627#M134978</guid>
      <dc:creator>manjunathmeti</dc:creator>
      <dc:date>2020-03-03T14:12:02Z</dc:date>
    </item>
    <item>
      <title>Re: How can Splunk loop through a list of numbers and do an action against each of them?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-Splunk-loop-through-a-list-of-numbers-and-do-an-action/m-p/481628#M134979</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;| makeresults count=999
| streamstats count 
| eval count=printf("%03d",count) 
| eval src_host="myhost".count
|lookup dnslookup clienthost as src_host OUTPUTNEW clientip
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hi, folks&lt;BR /&gt;
How about this?&lt;/P&gt;</description>
      <pubDate>Tue, 03 Mar 2020 19:28:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-Splunk-loop-through-a-list-of-numbers-and-do-an-action/m-p/481628#M134979</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-03-03T19:28:19Z</dc:date>
    </item>
  </channel>
</rss>

