<?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: ERROR Missing arguments to operator runshellscript expected at least 10 got 2 in Alerting</title>
    <link>https://community.splunk.com/t5/Alerting/ERROR-Missing-arguments-to-operator-runshellscript-expected-at/m-p/95630#M1379</link>
    <description>&lt;P&gt;does runscript command only works in alerts? so  I should create a search query, which has runscript command, in &lt;A href="http://splunk.xyz/en-US/app/search/search"&gt;http://splunk.xyz/en-US/app/search/search&lt;/A&gt; and then save it as alert?.&lt;/P&gt;

&lt;P&gt;I have directly tried this command in search GUI to saved the result but it does not return the results.csv.gz.&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;| head 1 | runshellscript test.py [ search * | stats count | return count ] 2 3 4 5 6 7 /var/www&lt;/LI&gt;
&lt;/UL&gt;</description>
    <pubDate>Fri, 02 Jun 2017 23:50:41 GMT</pubDate>
    <dc:creator>testadrianbelen</dc:creator>
    <dc:date>2017-06-02T23:50:41Z</dc:date>
    <item>
      <title>ERROR Missing arguments to operator runshellscript expected at least 10 got 2</title>
      <link>https://community.splunk.com/t5/Alerting/ERROR-Missing-arguments-to-operator-runshellscript-expected-at/m-p/95627#M1376</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I'm new at this triggering of alert scripts and have hit my first obstacle.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;When this search is manually fired in the Splunk GUI:

index=* sourcetype=df | multikv | eval perc_used=trim(UsePct, "%") | search perc_used &amp;gt;= 80 | runshellscript snow_alert.sh

Gives the following error message:

External search command 'runshellscript' returned error code 1. Script output = "ERROR "Missing arguments to operator 'runshellscript', expected at least 10, got 2." "

The script looks like this:

#! /bin/sh
#
#  ARGUMENTS
#  $0 Script name
#  $1 Number of events returned
#  $2 Search terms
#  $3 Fully qualified query string
#  $4 Name of saved search
#  $5 Trigger reason (for example, "The number of events was greater than 1")
#  $6 Browser URL to view the saved search
#  $8 File in which the results for this search are stored (contains raw results)
/opt/splunk/bin/splunk search "|snow instance=dev action=insert request=incident short_description=\"Alert filed by Splunk.\" work_notes=\"R
esults URL = $6\""

That script is in the correct location on the filesystem and I am able to run it at the CLI.

Example from the CLI:

opt/splunk/bin/splunk search "|snow instance=dev action=insert request=incident short_description=\"Alert filed by Splunk.\" work_notes=\"Results URL = $6\"" &amp;gt;&amp;gt; splunk-testing.log 2&amp;gt;&amp;amp;1

The following error is logged:

"External search command 'runshellscript' returned error code 1. Script output = "ERROR "Missing arguments to operator 'runshellscript', expected at least 10, got 2.""

It is mentioned here:
&lt;A href="http://wiki.splunk.com/Community:TroubleshootingAlertScripts" target="test_blank"&gt;http://wiki.splunk.com/Community:TroubleshootingAlertScripts&lt;/A&gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When I execute:&lt;/P&gt;

&lt;P&gt;echo "&lt;CODE&gt;date&lt;/CODE&gt; ARG0='$0' ARG1='$1' ARG2='$2' ARG3='$3' ARG4='$4' ARG5='$5' ARG6='$6' ARG7='$7' ARG8='$8'"&lt;/P&gt;

&lt;P&gt;I get:&lt;/P&gt;

&lt;P&gt;Tue Jan 22 12:43:32 PST 2013 ARG0='-bash' ARG1='' ARG2='' ARG3='' ARG4='' ARG5='' ARG6='' ARG7='' ARG8=''&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;What am I doing wrong?
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Jan 2013 20:32:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/ERROR-Missing-arguments-to-operator-runshellscript-expected-at/m-p/95627#M1376</guid>
      <dc:creator>multiverse</dc:creator>
      <dc:date>2013-01-22T20:32:30Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR Missing arguments to operator runshellscript expected at least 10 got 2</title>
      <link>https://community.splunk.com/t5/Alerting/ERROR-Missing-arguments-to-operator-runshellscript-expected-at/m-p/95628#M1377</link>
      <description>&lt;P&gt;That command is whats used when an alert script fires.  &lt;/P&gt;

&lt;P&gt;When an alert fires and there's a script to run those variables are passed to the script, along with a session key which is read from STDIN.&lt;/P&gt;

&lt;P&gt;For instance $4 is the saved search name - this can't be set because this isn't a saved search.&lt;/P&gt;

&lt;P&gt;If you save your search, and create an alert trigger to call your script - it will work.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Edit 1&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;Or ... create the variables yourself.&lt;/P&gt;

&lt;P&gt;Here the 1st argument is the number of results&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;* | head 1 | runshellscript echo.sh * | head 1 | runshellscript echo.sh [ search * | stats count | return count ] 2 3 4 5 6 7
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and it puts this in bin/scripts/echo_output.txt :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;'/opt/splunk/bin/scripts/echo.sh' 'count=64972' '2' '3' '4' '5' '6' '7' '/opt/splunk/var/run/splunk/dispatch/8/results.csv.gz' 'sessionKey=cedffc9ebc8cf266eb59a95156922ecd'
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Worth noting ..&lt;/P&gt;

&lt;P&gt;The script doesn't run against each row.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Edit 2&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;This is actually very, very cool&lt;/P&gt;

&lt;P&gt;providing you're careful with your search you can pass search results directly into the script.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; * | stats values(sourcetype) as types 
 | eval stuff=mvjoin(types,",")
 | map search="| runshellscript echo.sh \"$stuff$\" 2 3 4 5 6 7 8"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now echo.sh gets a comma delimited list of sourcetypes as the 1st argument.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jan 2013 21:10:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/ERROR-Missing-arguments-to-operator-runshellscript-expected-at/m-p/95628#M1377</guid>
      <dc:creator>jonuwz</dc:creator>
      <dc:date>2013-01-22T21:10:14Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR Missing arguments to operator runshellscript expected at least 10 got 2</title>
      <link>https://community.splunk.com/t5/Alerting/ERROR-Missing-arguments-to-operator-runshellscript-expected-at/m-p/95629#M1378</link>
      <description>&lt;P&gt;awesome discovery.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jan 2013 21:34:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/ERROR-Missing-arguments-to-operator-runshellscript-expected-at/m-p/95629#M1378</guid>
      <dc:creator>jonuwz</dc:creator>
      <dc:date>2013-01-22T21:34:08Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR Missing arguments to operator runshellscript expected at least 10 got 2</title>
      <link>https://community.splunk.com/t5/Alerting/ERROR-Missing-arguments-to-operator-runshellscript-expected-at/m-p/95630#M1379</link>
      <description>&lt;P&gt;does runscript command only works in alerts? so  I should create a search query, which has runscript command, in &lt;A href="http://splunk.xyz/en-US/app/search/search"&gt;http://splunk.xyz/en-US/app/search/search&lt;/A&gt; and then save it as alert?.&lt;/P&gt;

&lt;P&gt;I have directly tried this command in search GUI to saved the result but it does not return the results.csv.gz.&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;| head 1 | runshellscript test.py [ search * | stats count | return count ] 2 3 4 5 6 7 /var/www&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Fri, 02 Jun 2017 23:50:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/ERROR-Missing-arguments-to-operator-runshellscript-expected-at/m-p/95630#M1379</guid>
      <dc:creator>testadrianbelen</dc:creator>
      <dc:date>2017-06-02T23:50:41Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR Missing arguments to operator runshellscript expected at least 10 got 2</title>
      <link>https://community.splunk.com/t5/Alerting/ERROR-Missing-arguments-to-operator-runshellscript-expected-at/m-p/95631#M1380</link>
      <description>&lt;P&gt;I also saved the search as alert but it also does not work &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Jun 2017 01:31:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/ERROR-Missing-arguments-to-operator-runshellscript-expected-at/m-p/95631#M1380</guid>
      <dc:creator>testadrianbelen</dc:creator>
      <dc:date>2017-06-03T01:31:08Z</dc:date>
    </item>
  </channel>
</rss>

