Splunk Search

Passing dynamic parameters in search running from cli

bsrikanthreddy5
Path Finder

Hi, 

Is there was to dynamically pass a value like below in Splunk for running a search from cli.

I am trying to write a script to find event count from source files on HF and compare event to count indexed by running the below search 

/opt/splunk/bin/splunk search 'index=*  source=${c2_source}/*.gz  | stats count' -uri 'https://<SH IP>:8089/' -auth admin:xxxxxxxxxx  2>/dev/null

Or  is there way to achive using restapi commands

Labels (2)
Tags (1)
0 Karma

bsrikanthreddy5
Path Finder

I have implemented this way.

query="index=*  source=${c2_source}/*.gz earliest=-1d@d | stats count"

 event_count=$(/opt/splunk/bin/splunk search "$query" -uri 'https://<SH-IP>:8089/' -auth admin:password 2>/dev/null)

  echo $event_count

0 Karma

isoutamo
SplunkTrust
SplunkTrust
When you are using “ instead of ‘ those variables etc will be expanded on command line.
0 Karma
Get Updates on the Splunk Community!

Earn a $35 Gift Card for Answering our Splunk Admins & App Developer Survey

Survey for Splunk Admins and App Developers is open now! | Earn a $35 gift card!      Hello there,  Splunk ...

Continuing Innovation & New Integrations Unlock Full Stack Observability For Your ...

You’ve probably heard the latest about AppDynamics joining the Splunk Observability portfolio, deepening our ...

Monitoring Amazon Elastic Kubernetes Service (EKS)

As we’ve seen, integrating Kubernetes environments with Splunk Observability Cloud is a quick and easy way to ...