Splunk Search

How can I pass a variable to the tail command?

terryloar
Path Finder

...
| tail 200

works fine.
...
| eval tail_value=200
| tail tail_value

throws this error:
Error in 'tail' command: The number of results must be a positive number.

I've used tokens as the tail argument but a simple variable is not recognized. For example:
...
| tail $token_from_dropdown$

works.

We've written a cumbersome work-around, but I know I'm missing the simple solution.

Thanks.

0 Karma
1 Solution

jhupka
Path Finder

One possibility is to get the dynamic value via a subsearch:

index=_internal | tail [ | stats count | eval search=10 | fields search ]

That will effectively expand to a search that looks like this:

 index=_internal | tail ((10))

So in your case just come up with a subsearch that dynamically obtains your value.

View solution in original post

0 Karma

jhupka
Path Finder

One possibility is to get the dynamic value via a subsearch:

index=_internal | tail [ | stats count | eval search=10 | fields search ]

That will effectively expand to a search that looks like this:

 index=_internal | tail ((10))

So in your case just come up with a subsearch that dynamically obtains your value.

0 Karma

terryloar
Path Finder

Good, simple solution. Thanks.

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 ...