Splunk Search

How to search the logfile which name is dynamic like application_yyyymmdd.log

oolongcat
New Member

Hi Splunk support,

I have a set of log file which name as below: (today is 20170723)
application_20170721.log
application_20170722.log
application_20170723.log

In unix, it should be like application_date +%Y%m%d.log

in order to search the latest log file, what should the search command.

so that sth can be like source="application_date +%Y%m%d.log"

Tags (1)
0 Karma

HiroshiSatoh
Champion

How is this search sentence?

(your search)  [| tstats max(_time) as wk_time where sourcetype=(your sourcetype)|eval source="application_"+strftime(wk_time,"%Y%m%d")+".log"| fields source]

OR
where sourcetype=(your sourcetype)→where source="application_*.log"

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi oolongcat,
you could use

[monitor://your_path/application_*.log]
index = your_index
sourcetype = your_sourcetype
disabled = 0
ignoreOlderThan = 2d

In this way you have all events of last two days (or a different time range) and not older.

Bye.
Giuseppe

0 Karma

oolongcat
New Member

Hi Cusello,

Thanks for you reply.

your way seems will ignore all the log file which older than 2 days, but this is not what I want.

Is there any way like as below:

[search source="application_" +strftime(time(),"%Y%m%d") + ".log"]

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...