<?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 do I generate many output csv files from a single search ? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-generate-many-output-csv-files-from-a-single-search/m-p/51335#M12399</link>
    <description>&lt;P&gt;I Fired the command on search box but I am getting error&lt;BR /&gt;
Error in 'script' command: Cannot find program 'mydistrib' or script 'mydistrib'.&lt;/P&gt;

&lt;P&gt;I have copied the distrib.pl in \splunk\etc\apps\search\scripts&lt;/P&gt;

&lt;P&gt;and I have two conf file and the path is \Splunk\etc\system\default and the second ones path is&lt;BR /&gt;
\Splunk\etc\apps\search\default&lt;/P&gt;</description>
    <pubDate>Thu, 28 Nov 2013 12:57:34 GMT</pubDate>
    <dc:creator>gladiatorankit</dc:creator>
    <dc:date>2013-11-28T12:57:34Z</dc:date>
    <item>
      <title>How do I generate many output csv files from a single search ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-generate-many-output-csv-files-from-a-single-search/m-p/51332#M12396</link>
      <description>&lt;P&gt;I am reviewing the scheduled jobs on our Splunk system and I noticed that several people are running the same query many times and extracting something slightly different each time.&lt;/P&gt;&lt;BR /&gt;
With each query taking 5-10 minutes each in the off hours, I can save a lot of time by running the search only once.  I can do this in a view, but don't know how to do it in a search.&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;
Any suggestions?&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Aug 2011 15:42:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-generate-many-output-csv-files-from-a-single-search/m-p/51332#M12396</guid>
      <dc:creator>fk319</dc:creator>
      <dc:date>2011-08-01T15:42:59Z</dc:date>
    </item>
    <item>
      <title>Re: How do I generate many output csv files from a single search ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-generate-many-output-csv-files-from-a-single-search/m-p/51333#M12397</link>
      <description>&lt;P&gt;&lt;STRONG&gt;index=&lt;/STRONG&gt;(what ever you index) &lt;STRONG&gt;| convert ctime(_time) as timestamp | table&lt;/STRONG&gt; EXAMPLE (timestamp name signature src spt dst dpt) &lt;EM&gt;what ever field sets you want to bring back&lt;/EM&gt;)** | sendmail to=&lt;STRONG&gt;&lt;A href="mailto:youremailaddress@email.com"&gt;youremailaddress@email.com&lt;/A&gt; **server=&lt;/STRONG&gt;(your mail server)** sendresults=true inline=false graceful=true**&lt;/P&gt;

&lt;P&gt;Everything in bold are your main commands. Also, you put in this command &lt;STRONG&gt;| convert ctime(_time) as timestamp&lt;/STRONG&gt; when you care about the time stamp. By default the time will not come out right when you output to CSV, therefore the need for the command. &lt;/P&gt;</description>
      <pubDate>Sat, 01 Oct 2011 20:24:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-generate-many-output-csv-files-from-a-single-search/m-p/51333#M12397</guid>
      <dc:creator>peppersprayy</dc:creator>
      <dc:date>2011-10-01T20:24:12Z</dc:date>
    </item>
    <item>
      <title>Re: How do I generate many output csv files from a single search ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-generate-many-output-csv-files-from-a-single-search/m-p/51334#M12398</link>
      <description>&lt;P&gt;Your subject mentions writing csv files, so I assume you really do want your data ultimately to come out of the Splunk system and go into several identical copies on your real filesystem.&lt;/P&gt;

&lt;P&gt;I would run the one search and pipe it through a custom command that simply writes the data out to several output files.&lt;/P&gt;

&lt;P&gt;Here are some samples to start in case you haven't worked with them before (and this is off the top of my head, so beware a random syntax problem... also note that the Splunk documentation on this stuff is a bit convoluted and seems to have some problems):&lt;/P&gt;

&lt;P&gt;After the below steps are done, you would run your search and add    | script perl mydistrib   to the end.&lt;/P&gt;

&lt;P&gt;To get set up:&lt;/P&gt;

&lt;P&gt;Add an entry to your commands.conf file&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[mydistrib] 
filename=distrib.pl
type=perl
retainsevents=yes
streaming=no
enableheader=false
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then in your /ops/splunk/etc/searchscripts directory, create a script named the same as "filename" above.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;#!/usr/bin/perl

@outfiles = ("/path1/file1","/path2/file2","/path3/file3");
$main_out = "/path/to/primary/outfile";

open(OUTFILE,"&amp;gt;$main_out) or die "Cannot open $main_out for writing\n";

# Copy everything Splunk sends via STDIN to a master output file
while (&amp;lt;&amp;gt;) {
   print OUTFILE "$_";
}
close OUTFILE;

# Now just duplicate the file.
foreach $target (@outfiles) {
   system("cp $main_out $target");
}
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 01 Oct 2011 22:07:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-generate-many-output-csv-files-from-a-single-search/m-p/51334#M12398</guid>
      <dc:creator>Sqig</dc:creator>
      <dc:date>2011-10-01T22:07:08Z</dc:date>
    </item>
    <item>
      <title>Re: How do I generate many output csv files from a single search ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-generate-many-output-csv-files-from-a-single-search/m-p/51335#M12399</link>
      <description>&lt;P&gt;I Fired the command on search box but I am getting error&lt;BR /&gt;
Error in 'script' command: Cannot find program 'mydistrib' or script 'mydistrib'.&lt;/P&gt;

&lt;P&gt;I have copied the distrib.pl in \splunk\etc\apps\search\scripts&lt;/P&gt;

&lt;P&gt;and I have two conf file and the path is \Splunk\etc\system\default and the second ones path is&lt;BR /&gt;
\Splunk\etc\apps\search\default&lt;/P&gt;</description>
      <pubDate>Thu, 28 Nov 2013 12:57:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-generate-many-output-csv-files-from-a-single-search/m-p/51335#M12399</guid>
      <dc:creator>gladiatorankit</dc:creator>
      <dc:date>2013-11-28T12:57:34Z</dc:date>
    </item>
  </channel>
</rss>

