Splunk Search

Specifying today's date in the source file on a search

DavidGuarneri
Path Finder

Is there a way to specify today's date in the filename of the source on the search? I'm thinking in the same way you would put it in a bash script. Pseudocode:

source="C:logs\\path\\iislog_(time(%y%m%d)).log"

Tags (2)
0 Karma

yannK
Splunk Employee
Splunk Employee

use the function now() in a subsearch or a macro.

the search to generate a condition :

| stats count | eval date=strftime(now(),"%Y%m%d") | eval source="C:logs\\path\\iislog_".date.".log" | table source

the search using the sub search to generate a source condition

* [ | stats count | eval date=strftime(now(),"%Y%m%d") | eval source="C:logs\\path\\iislog_".date.".log" | table source]

you could improve by using a macro too.

Ayn
Legend

Use a subsearch:

[| stats count | eval source="C:\\logs\\path\\iislog".strftime(now(),"%y%m%d").".log" | fields source]

DavidGuarneri
Path Finder

That worked, thank you!

0 Karma

yannK
Splunk Employee
Splunk Employee

You are a kung fu master Ayn !

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...