Getting Data In

Start Splunk using batch file

harishalipaka
Motivator

Hi all,
I want splunk start using batch script ,when splunk is stopped..
I tried like this ..
when splunk status is stopped it will autometically run batch file to splunk start..

set PATH=C:\Program Files\Splunk\bin\splunk status
ECHO %PATH% 
PAUSE
if  %PATH% == splunk is stopped (
   change it
restart splunk
)  
Thanks
Harish
Tags (2)
0 Karma
1 Solution

harishalipaka
Motivator

thanks for your efforts..
This is my answer

set root=C:\Program Files\SplunkUniversalForwarder\bin
cd/
cd  %root% 
splunk start

finally i got but i dont know where can i store batch file in splunk.

Thanks
Harish

View solution in original post

harishalipaka
Motivator

thanks for your efforts..
This is my answer

set root=C:\Program Files\SplunkUniversalForwarder\bin
cd/
cd  %root% 
splunk start

finally i got but i dont know where can i store batch file in splunk.

Thanks
Harish

niketn
Legend

You can use Windows Service Configuration Manager to do this. Following seems to be a working script based off one of the answers on Stack Overflow https://stackoverflow.com/questions/3325081/how-to-check-if-a-service-is-running-via-batch-file-and-...

@Echo Off
set path="%WINDIR%\system32"
set ServiceName=splunkd

sc queryex "%ServiceName%"|Find "STATE"|Find /v "RUNNING">Nul&&(
    echo %ServiceName% not running 
    echo Start %ServiceName%

    Net start "%ServiceName%">nul||(
        Echo "%ServiceName%" did not start 
        exit /b 1
    )
    echo "%ServiceName%" started
    exit /b 0
)||(
    echo "%ServiceName%" Running
    exit /b 0
)

Please try out and confirm. PS: I have set the path to Windows system32 folder since the same is required to run sc and net start commands.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Agent Mode Engaged! Enchaining Agentic Operations with Splunk AI Assistant 2.0

    Are you ready to transform how your team handles complex data requests? We invite you to our upcoming ...

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...