Splunk Search

Does anyone have an example of a custom alert action script that uses a bash script?

gregbo
Communicator

All the ones I ever see is Python. I need one that uses a bash script.

0 Karma

Azeemering
Builder

my_custom_action.sh

 #!/bin/bash
 ResultsList=$(cat $8|gzip -d|tail -n +2)
 echo $ResultsList > output.txt

Taking each command as it comes:

ResultsList will contain the results of your Splunk search

cat $8 when splunk executes your script the $8 parameter will be the path of the search results on your server. Cat will output the contents of the file and pass it to:

gzip -d - this will decompress the results to make them readable, and then:

tail -n +2 - will ignore the top line which is the header, and start reading from line 2!

echo $ResultsList will write the results of the above into output.txt for you to review.

0 Karma
Get Updates on the Splunk Community!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...