<?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 How do I get the parameters passed to the batch script in an alert action? in Alerting</title>
    <link>https://community.splunk.com/t5/Alerting/How-do-I-get-the-parameters-passed-to-the-batch-script-in-an/m-p/201384#M3504</link>
    <description>&lt;P&gt;I have a .bat script that calls a Powershell script as an alert action. I am trying to make my batch script re-usable with different parameters from Alert actions. &lt;/P&gt;

&lt;P&gt;My batch script is like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;@echo off
set psdir=E:\Temp\%1
E:
@powershell %psdir%
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When I run the batch script from CMD with parameters, I have no issues, PS runs great and it does what it needs to do.&lt;BR /&gt;
If I hard code the PS path and run BAT as an alert action without parameters, it works as well. &lt;/P&gt;

&lt;P&gt;When I try to run it from Alert actions with parameters, it fails. My bat file is located in Splunk_Home\bin\scripts&lt;BR /&gt;
Alert action is like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;mybat.bat myps1.ps1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks up front for your time and help. &lt;/P&gt;</description>
    <pubDate>Wed, 08 Jun 2016 21:05:44 GMT</pubDate>
    <dc:creator>axl88</dc:creator>
    <dc:date>2016-06-08T21:05:44Z</dc:date>
    <item>
      <title>How do I get the parameters passed to the batch script in an alert action?</title>
      <link>https://community.splunk.com/t5/Alerting/How-do-I-get-the-parameters-passed-to-the-batch-script-in-an/m-p/201384#M3504</link>
      <description>&lt;P&gt;I have a .bat script that calls a Powershell script as an alert action. I am trying to make my batch script re-usable with different parameters from Alert actions. &lt;/P&gt;

&lt;P&gt;My batch script is like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;@echo off
set psdir=E:\Temp\%1
E:
@powershell %psdir%
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When I run the batch script from CMD with parameters, I have no issues, PS runs great and it does what it needs to do.&lt;BR /&gt;
If I hard code the PS path and run BAT as an alert action without parameters, it works as well. &lt;/P&gt;

&lt;P&gt;When I try to run it from Alert actions with parameters, it fails. My bat file is located in Splunk_Home\bin\scripts&lt;BR /&gt;
Alert action is like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;mybat.bat myps1.ps1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks up front for your time and help. &lt;/P&gt;</description>
      <pubDate>Wed, 08 Jun 2016 21:05:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-do-I-get-the-parameters-passed-to-the-batch-script-in-an/m-p/201384#M3504</guid>
      <dc:creator>axl88</dc:creator>
      <dc:date>2016-06-08T21:05:44Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get the parameters passed to the batch script in an alert action?</title>
      <link>https://community.splunk.com/t5/Alerting/How-do-I-get-the-parameters-passed-to-the-batch-script-in-an/m-p/201385#M3505</link>
      <description>&lt;P&gt;You should avoid such solution using an argument for post script alert. Splunk will pass required arguments. Maybe your batch script can decided which powershell script to run based on saved search name passed from Splunk. &lt;/P&gt;</description>
      <pubDate>Wed, 08 Jun 2016 21:54:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-do-I-get-the-parameters-passed-to-the-batch-script-in-an/m-p/201385#M3505</guid>
      <dc:creator>Masa</dc:creator>
      <dc:date>2016-06-08T21:54:37Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get the parameters passed to the batch script in an alert action?</title>
      <link>https://community.splunk.com/t5/Alerting/How-do-I-get-the-parameters-passed-to-the-batch-script-in-an/m-p/201386#M3506</link>
      <description>&lt;P&gt;Thanks for the response. Reason I came up with this solution is to add/remove PS scripts without Splunk server intervention. I just want to use UI setup for alerts going forward and keep my PS scripts somewhere that Splunk server can access. &lt;BR /&gt;
I was wondering if "\" (backslashes) of the path might be the problem for Splunk. Can I escape them as regex? &lt;/P&gt;</description>
      <pubDate>Wed, 08 Jun 2016 22:32:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-do-I-get-the-parameters-passed-to-the-batch-script-in-an/m-p/201386#M3506</guid>
      <dc:creator>axl88</dc:creator>
      <dc:date>2016-06-08T22:32:21Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get the parameters passed to the batch script in an alert action?</title>
      <link>https://community.splunk.com/t5/Alerting/How-do-I-get-the-parameters-passed-to-the-batch-script-in-an/m-p/201387#M3507</link>
      <description>&lt;P&gt;Your idea itself sounds good.&lt;BR /&gt;
Sorry but the UI input for post script is to check executable file (script) in a proper location. So, you need to avoid argument in the Alert action script field. &lt;/P&gt;</description>
      <pubDate>Wed, 08 Jun 2016 22:47:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-do-I-get-the-parameters-passed-to-the-batch-script-in-an/m-p/201387#M3507</guid>
      <dc:creator>Masa</dc:creator>
      <dc:date>2016-06-08T22:47:36Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get the parameters passed to the batch script in an alert action?</title>
      <link>https://community.splunk.com/t5/Alerting/How-do-I-get-the-parameters-passed-to-the-batch-script-in-an/m-p/201388#M3508</link>
      <description>&lt;P&gt;ok, this question might be unrelated to what i ask, but do you know if there is anyway to run a saved search as alert action like post script? &lt;/P&gt;</description>
      <pubDate>Thu, 09 Jun 2016 16:04:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-do-I-get-the-parameters-passed-to-the-batch-script-in-an/m-p/201388#M3508</guid>
      <dc:creator>axl88</dc:creator>
      <dc:date>2016-06-09T16:04:05Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get the parameters passed to the batch script in an alert action?</title>
      <link>https://community.splunk.com/t5/Alerting/How-do-I-get-the-parameters-passed-to-the-batch-script-in-an/m-p/201389#M3509</link>
      <description>&lt;P&gt;( ref: &lt;A href="https://answers.splunk.com/answers/2378/running-a-saved-search-from-the-command-line-interface-cli.html" target="_blank"&gt;https://answers.splunk.com/answers/2378/running-a-saved-search-from-the-command-line-interface-cli.html&lt;/A&gt; )&lt;/P&gt;

&lt;P&gt;In a script, run a Splunk search,&lt;BR /&gt;
    $SPLUNK_HOME/bin/splunk search '| savedsearch "$saved_search_name$" -app $my_app_name$' -auth admin:changeme&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 09:55:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-do-I-get-the-parameters-passed-to-the-batch-script-in-an/m-p/201389#M3509</guid>
      <dc:creator>Masa</dc:creator>
      <dc:date>2020-09-29T09:55:57Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get the parameters passed to the batch script in an alert action?</title>
      <link>https://community.splunk.com/t5/Alerting/How-do-I-get-the-parameters-passed-to-the-batch-script-in-an/m-p/201390#M3510</link>
      <description>&lt;P&gt;Thanks man&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jun 2016 17:18:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-do-I-get-the-parameters-passed-to-the-batch-script-in-an/m-p/201390#M3510</guid>
      <dc:creator>axl88</dc:creator>
      <dc:date>2016-06-09T17:18:20Z</dc:date>
    </item>
  </channel>
</rss>

