Deployment Architecture

Variable for Splunk install directory in deployed scripts

rtadams89
Contributor

I need to run a vbs script on some of my Windows Forwarders. To do so, I have deployed a batch script that calls the vbs script with the following code:

@echo off
cscript //nologo "C:\Program Files\SplunkUniversalForwarder\etc\apps\my-test-app\bin\script.vbs"

The problem is that the Splunk Universal Forwarder may be running from a location other than c:\program files.

Is there any way to get the directory Splunk is running from within the bat wrapper script and use that to provide the correct path to the vbs script file?

PS: I am aware of the environmental variables for "Program Files", but I would like to cover the cases where Splunk is installed to an arbitrary directory, perhaps not even in the Program Files folder.

Tags (1)
0 Karma
1 Solution

rtadams89
Contributor

Figured it out. I ended up using the variable "%~dp0" inside the patch script. This will return the path to the directory the batch script is located in. By appending the name of my vbs file to that, I end up with the full path to the vbs file.

View solution in original post

rtadams89
Contributor

Figured it out. I ended up using the variable "%~dp0" inside the patch script. This will return the path to the directory the batch script is located in. By appending the name of my vbs file to that, I end up with the full path to the vbs file.

rtadams89
Contributor

Because inputs.conf supports the $SPLUNK_HOME variable.

0 Karma

linu1988
Champion

Then how are you going to configure the scripts in inputs.conf? If you are just looking for the directory, a simple vb script to check on the splunk registry to get the installed path.

0 Karma

rtadams89
Contributor

I don't know where Splunk is installed on each host.

0 Karma

linu1988
Champion

Why not declare a environment variable as you know where the splunk forwarder installed. and replace them until \etc. Any reason why it can't happen?

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Take Action Automatically on Splunk Alerts with Red Hat Ansible Automation Platform

 Are you ready to revolutionize your IT operations? As digital transformation accelerates, the demand for ...

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...