<?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 to call $SPLUNK_HOME or %SPLUNK_HOME% from a .bat file for Windows Scripted input? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-to-call-SPLUNK-HOME-or-SPLUNK-HOME-from-a-bat-file-for/m-p/385061#M69202</link>
    <description>&lt;P&gt;Hi @rob_jordan,&lt;/P&gt;

&lt;P&gt;Make sure you've defined the &lt;CODE&gt;%SPLUNK_HOME%&lt;/CODE&gt; as a variable on your windows or you won't be able to use it from a &lt;CODE&gt;.bat&lt;/CODE&gt;script since it's actually a Splunk defined variable  :&lt;BR /&gt;
&lt;A href="https://stackoverflow.com/questions/5898131/set-a-persistent-environment-variable-from-cmd-exe"&gt;https://stackoverflow.com/questions/5898131/set-a-persistent-environment-variable-from-cmd-exe&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;If you want to use a relative path as follows &lt;CODE&gt;..\..\..\..\bin\splunk.exe&lt;/CODE&gt; my advise is to output an &lt;CODE&gt;ls&lt;/CODE&gt; from the script and see if you are hitting the right folder. &lt;/P&gt;

&lt;P&gt;Cheers,&lt;BR /&gt;
David&lt;/P&gt;</description>
    <pubDate>Thu, 23 May 2019 05:40:41 GMT</pubDate>
    <dc:creator>DavidHourani</dc:creator>
    <dc:date>2019-05-23T05:40:41Z</dc:date>
    <item>
      <title>How to call $SPLUNK_HOME or %SPLUNK_HOME% from a .bat file for Windows Scripted input?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-call-SPLUNK-HOME-or-SPLUNK-HOME-from-a-bat-file-for/m-p/385060#M69201</link>
      <description>&lt;P&gt;I have a working scripted input using the first method below, however I'm wanting to get rid of the hard coding of SPLUNK_HOME and make it dynamic as sometimes Splunk is installed in different locations. I tried 3 different dynamic variations which all fail with the following message in the splunkd.log &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;ERROR ExecProcessor - message from ""C:\Program Files\Splunk\etc\apps\TA-btool-Win\bin\TA-btool.bat"" The filename, directory name, or volume label syntax is incorrect.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;.bat file below&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;#TA-btool.bat
# working, however, using a hard coded path
"C:\Program Files\SplunkUniversalForwarder\bin\splunk.exe" btool --debug outputs list

# fails
"%SPLUNK_HOME%\bin\splunk.exe" btool --debug outputs list

# fails
"$SPLUNK_HOME\bin\splunk.exe" btool --debug outputs list

# fails
"..\..\..\..\bin\splunk.exe" btool --debug outputs list
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;inputs.conf file below&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[script://.\bin\TA-btool.bat]
disabled = 0
# set index below which will receive events - defaults to main
#index = splunk_admin_p
 # every 60 seconds
#interval = 60.0
# every 5 minutes
#interval = 300.0
# every hour
#interval = 6000
# once a day - default
interval = 86400.0
# 15 minutes
#interval = 900
sourcetype = ta_btool
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You can alternatively grab my Windows TA/scripted input here:  &lt;A href="http://downloads.jordan2000.com/splunk/TA-btool-Win.tgz"&gt;http://downloads.jordan2000.com/splunk/TA-btool-Win.tgz&lt;/A&gt;&lt;BR /&gt;
and a Linux version which could be used for comparison: &lt;A href="http://downloads.jordan2000.com/splunk/TA-btool-Linux.tgz"&gt;http://downloads.jordan2000.com/splunk/TA-btool-Linux.tgz&lt;/A&gt;&lt;BR /&gt;
btw, the Linux .sh version works just fine using $SPLUNK_HOME - I just couldn't solve how to do the equivalent on Windows using a .bat.&lt;/P&gt;

&lt;P&gt;I will award Karma points to a working solution for the .bat file&lt;/P&gt;

&lt;P&gt;Thanks,&lt;/P&gt;

&lt;P&gt;Rob&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2019 18:00:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-call-SPLUNK-HOME-or-SPLUNK-HOME-from-a-bat-file-for/m-p/385060#M69201</guid>
      <dc:creator>bandit</dc:creator>
      <dc:date>2019-05-22T18:00:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to call $SPLUNK_HOME or %SPLUNK_HOME% from a .bat file for Windows Scripted input?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-call-SPLUNK-HOME-or-SPLUNK-HOME-from-a-bat-file-for/m-p/385061#M69202</link>
      <description>&lt;P&gt;Hi @rob_jordan,&lt;/P&gt;

&lt;P&gt;Make sure you've defined the &lt;CODE&gt;%SPLUNK_HOME%&lt;/CODE&gt; as a variable on your windows or you won't be able to use it from a &lt;CODE&gt;.bat&lt;/CODE&gt;script since it's actually a Splunk defined variable  :&lt;BR /&gt;
&lt;A href="https://stackoverflow.com/questions/5898131/set-a-persistent-environment-variable-from-cmd-exe"&gt;https://stackoverflow.com/questions/5898131/set-a-persistent-environment-variable-from-cmd-exe&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;If you want to use a relative path as follows &lt;CODE&gt;..\..\..\..\bin\splunk.exe&lt;/CODE&gt; my advise is to output an &lt;CODE&gt;ls&lt;/CODE&gt; from the script and see if you are hitting the right folder. &lt;/P&gt;

&lt;P&gt;Cheers,&lt;BR /&gt;
David&lt;/P&gt;</description>
      <pubDate>Thu, 23 May 2019 05:40:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-call-SPLUNK-HOME-or-SPLUNK-HOME-from-a-bat-file-for/m-p/385061#M69202</guid>
      <dc:creator>DavidHourani</dc:creator>
      <dc:date>2019-05-23T05:40:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to call $SPLUNK_HOME or %SPLUNK_HOME% from a .bat file for Windows Scripted input?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-call-SPLUNK-HOME-or-SPLUNK-HOME-from-a-bat-file-for/m-p/385062#M69203</link>
      <description>&lt;P&gt;hi rob,&lt;BR /&gt;
In your script, if you change to&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;REM  This will get the splunk.exe path dynamically within a bat file. 
for /f "delims=" %%a in ('where /r c:\ splunk.exe') do @set SPLUNK_EXE=%%a

%SPLUNK_EXE% btool inputs list --debug
%SPLUNK_EXE% btool outputs list --debug
..
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and so on for Windows&lt;/P&gt;

&lt;P&gt;Also another improvement you could do is to provide  (inputs, outputs, limits,  props) as a list and call in a for loop within .bat file&lt;BR /&gt;
something like below&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;FOR %%CONFS IN (inputs, outputs, limits,  props) DO (
 %SPLUNK_EXE% btool %CONFS% list --debug
)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 May 2019 10:49:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-call-SPLUNK-HOME-or-SPLUNK-HOME-from-a-bat-file-for/m-p/385062#M69203</guid>
      <dc:creator>koshyk</dc:creator>
      <dc:date>2019-05-23T10:49:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to call $SPLUNK_HOME or %SPLUNK_HOME% from a .bat file for Windows Scripted input?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-call-SPLUNK-HOME-or-SPLUNK-HOME-from-a-bat-file-for/m-p/385063#M69204</link>
      <description>&lt;P&gt;Thanks or you suggestions, @DavidHourani Should %SPLUNK_HOME% already be set by the parent process since this is a process being spawned as a scripted input by a either Splunk or the Splunk Universal Forwarder?&lt;/P&gt;</description>
      <pubDate>Thu, 23 May 2019 13:58:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-call-SPLUNK-HOME-or-SPLUNK-HOME-from-a-bat-file-for/m-p/385063#M69204</guid>
      <dc:creator>bandit</dc:creator>
      <dc:date>2019-05-23T13:58:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to call $SPLUNK_HOME or %SPLUNK_HOME% from a .bat file for Windows Scripted input?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-call-SPLUNK-HOME-or-SPLUNK-HOME-from-a-bat-file-for/m-p/385064#M69205</link>
      <description>&lt;P&gt;Thanks for the ideas, @koshyk. The where command seems fairly intense on my Windows workstation CPU to recursively look for splunk.exe so I don't think I could push out to the Universal Forwarders on Windows servers.&lt;/P&gt;</description>
      <pubDate>Thu, 23 May 2019 14:03:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-call-SPLUNK-HOME-or-SPLUNK-HOME-from-a-bat-file-for/m-p/385064#M69205</guid>
      <dc:creator>bandit</dc:creator>
      <dc:date>2019-05-23T14:03:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to call $SPLUNK_HOME or %SPLUNK_HOME% from a .bat file for Windows Scripted input?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-call-SPLUNK-HOME-or-SPLUNK-HOME-from-a-bat-file-for/m-p/385065#M69206</link>
      <description>&lt;P&gt;Hi @rob_jordan, no it wont be inherited for scripted inputs &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt; did you get any info about the path using echo on the different commands you were using ? &lt;/P&gt;</description>
      <pubDate>Thu, 23 May 2019 14:14:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-call-SPLUNK-HOME-or-SPLUNK-HOME-from-a-bat-file-for/m-p/385065#M69206</guid>
      <dc:creator>DavidHourani</dc:creator>
      <dc:date>2019-05-23T14:14:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to call $SPLUNK_HOME or %SPLUNK_HOME% from a .bat file for Windows Scripted input?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-call-SPLUNK-HOME-or-SPLUNK-HOME-from-a-bat-file-for/m-p/385066#M69207</link>
      <description>&lt;P&gt;BTW, on Linux it does seem to have $SPLUNK_HOME available to it. It may very well be different on Windows. I was able to add the following statement to my .bat file.&lt;/P&gt;

&lt;P&gt;echo %SPLUNK_HOME%&lt;/P&gt;

&lt;P&gt;and it did return back a valid value.&lt;/P&gt;

&lt;P&gt;The following showed up in the event indexed by Splunk.&lt;BR /&gt;
C:\WINDOWS\system32&amp;gt;echo C:\Program Files\Splunk &lt;BR /&gt;
C:\Program Files\Splunk&lt;/P&gt;

&lt;P&gt;This leads me to think that I have a minor issue with surrounding the command or portions of the command with double or single quotes, etc. so it's properly interpreted at run time.&lt;/P&gt;

&lt;P&gt;Thanks,&lt;/P&gt;

&lt;P&gt;Rob&lt;/P&gt;</description>
      <pubDate>Thu, 23 May 2019 14:49:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-call-SPLUNK-HOME-or-SPLUNK-HOME-from-a-bat-file-for/m-p/385066#M69207</guid>
      <dc:creator>bandit</dc:creator>
      <dc:date>2019-05-23T14:49:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to call $SPLUNK_HOME or %SPLUNK_HOME% from a .bat file for Windows Scripted input?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-call-SPLUNK-HOME-or-SPLUNK-HOME-from-a-bat-file-for/m-p/385067#M69208</link>
      <description>&lt;P&gt;I must have had a typo somewhere or possibly had bad statements mixed with good. Ultimately, I got it to work with the following format in my .bat file.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"%SPLUNK_HOME%\bin\splunk.exe" btool --debug inputs list

"%SPLUNK_HOME%\bin\splunk.exe" btool --debug outputs list

"%SPLUNK_HOME%\bin\splunk.exe" btool --debug props list

"%SPLUNK_HOME%\bin\splunk.exe" btool --debug limits list

"%SPLUNK_HOME%\splunk.exe" btool --debug server list

"%SPLUNK_HOME%\bin\splunk.exe" btool --debug web list

"%SPLUNK_HOME%\bin\splunk.exe" btool --debug deploymentclient list
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 May 2019 15:13:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-call-SPLUNK-HOME-or-SPLUNK-HOME-from-a-bat-file-for/m-p/385067#M69208</guid>
      <dc:creator>bandit</dc:creator>
      <dc:date>2019-05-23T15:13:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to call $SPLUNK_HOME or %SPLUNK_HOME% from a .bat file for Windows Scripted input?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-call-SPLUNK-HOME-or-SPLUNK-HOME-from-a-bat-file-for/m-p/385068#M69209</link>
      <description>&lt;P&gt;To load Windows system variables&lt;BR /&gt;
use %SPLUNK_HOME%&lt;/P&gt;

&lt;P&gt;But it does not recognize the blank.&lt;BR /&gt;
ex) C:\Program Files\Splunk&lt;/P&gt;

&lt;P&gt;So we need to change&lt;BR /&gt;
ex)C:\\"Program Files\"\Splunk&lt;/P&gt;

&lt;P&gt;or&lt;/P&gt;

&lt;P&gt;You use Windows system variables&lt;BR /&gt;
ex) set SPLUNK_HOME="C:\Program Files\Splunk"&lt;BR /&gt;
need double quotes&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2019 02:48:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-call-SPLUNK-HOME-or-SPLUNK-HOME-from-a-bat-file-for/m-p/385068#M69209</guid>
      <dc:creator>moregorenine</dc:creator>
      <dc:date>2019-12-18T02:48:17Z</dc:date>
    </item>
  </channel>
</rss>

