Splunk Search

combine two searches

msalghamdi
Path Finder

Dear Splunker

i need a search that gets me if  theres a host that has these logs, below is a psudeo search that show what i really want:

index=linux host=* sourcetype=bash_history AND ("systemctl start" OR "systemctl enable") | union [search index=linux host=* sourcetype=bash_history (mv AND /opt/ ) ]

just to make more clearer, i want a match only  if a server generated a log that contains "mv AND /opt/" and another log that contains "systemctl start" OR "systemctl enable"

 

 

 

thanks in advance

Labels (2)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this

index=linux host=* sourcetype=bash_history "systemctl start" OR "systemctl enable" OR (mv /opt/)
| eval systemctl=if(searchmatch("systemctl"), "systemctl",null())
| eval mo_opt=if(searchmatch("mv") AND searchmatch("/opt/"), "mv_opt", null())
| stats dc(mv_opt) as mv_opt dc(systemctl) as systemctl by host
| where mv_opt==1 and systemctl==1

View solution in original post

msalghamdi
Path Finder

it worked, thanks Whisperer, a helping hand as alwas

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this

index=linux host=* sourcetype=bash_history "systemctl start" OR "systemctl enable" OR (mv /opt/)
| eval systemctl=if(searchmatch("systemctl"), "systemctl",null())
| eval mo_opt=if(searchmatch("mv") AND searchmatch("/opt/"), "mv_opt", null())
| stats dc(mv_opt) as mv_opt dc(systemctl) as systemctl by host
| where mv_opt==1 and systemctl==1
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

.conf25 Global Broadcast: Don’t Miss a Moment

Hello Splunkers, .conf25 is only a click away.  Not able to make it to .conf25 in person? No worries, you can ...

Observe and Secure All Apps with Splunk

 Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...

What's New in Splunk Observability - August 2025

What's New We are excited to announce the latest enhancements to Splunk Observability Cloud as well as what is ...