Getting Data In

Can REST API be used to execute a Bash script on Splunk server?

jingqin
New Member

I have a Bash script on my deployment server to add server into the serverclass.conf. Could I execute the bash script from a client using the Splunk REST API?

0 Karma
1 Solution

damien_chillet
Builder

You could execute a bash script using the Splunk REST API.

You would have to develop a custom search command "runscript" which would run the script and use the API to run a search ("| runscript").

Link to Splunk Dev on how to create custom search commands: http://dev.splunk.com/view/python-sdk/SP-CAAAEU2
A good recent app example that use custom search command to run btool: https://splunkbase.splunk.com/app/3923/

View solution in original post

0 Karma

damien_chillet
Builder

You could execute a bash script using the Splunk REST API.

You would have to develop a custom search command "runscript" which would run the script and use the API to run a search ("| runscript").

Link to Splunk Dev on how to create custom search commands: http://dev.splunk.com/view/python-sdk/SP-CAAAEU2
A good recent app example that use custom search command to run btool: https://splunkbase.splunk.com/app/3923/

0 Karma

jingqin
New Member

Emm.....but I would like to execute it from another server instead of search query. How can i achieve it?

0 Karma

damien_chillet
Builder

Well, if you define the command on the deployment server you can simply run something like the following from the client:

curl -d search="| runscript" https://deployment.server:8089/services/search/jobs -u admin:change
0 Karma

jingqin
New Member

is that work for bash script? I only see python script in the document...

0 Karma
Get Updates on the Splunk Community!

Detecting Remote Code Executions With the Splunk Threat Research Team

REGISTER NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If ...

Observability | Use Synthetic Monitoring for Website Metadata Verification

If you are on Splunk Observability Cloud, you may already have Synthetic Monitoringin your observability ...

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...