Getting Data In

How to ask Splunk to index a file using the CLI?

hiddenkirby
Contributor

Other than the oneshot... how would one toss a file into an index through the CLI?

I likely missed it in the documentation, but i couldn't find it.

Is there a rest endpoint to do the same?

maybe oneshot is the only solution to that?

1 Solution

hexx
Splunk Employee
Splunk Employee

If you intend to index the file instead of having Splunk monitoring/tailing it, then I think the CLI "oneshot" command is indeed the best solution.

# splunk add oneshot <path_to_your_file>

You could also create a new monitor input for that file from the CLI, this will index your file but it won't be at all the same than "uploading" it to Splunk as a one-time thing, as Splunk will be keeping track of it.

# splunk add monitor <path_to_your_file>

Another possibility is to toss the file in $SPLUNK_HOME/var/spool/splunk which is set up by default as a batch input (see $SPLUNK_HOME/etc/system/default/inputs.conf). Note that the file will be indexed destructively, so you may want to copy it there, not move it.

View solution in original post

sdwilkerson
Contributor

Hiddenkirby,
You can also use the built-in sinkhole "$SPLUNK_HOME/var/spool/splunk" to index a file in an ad-hoc fashion. Place any applicable file in there and it will be indexed by Splunk. Historically you could not control how those files were indexed, but now you can.

Just add an extra line to the top of your file that looks something like this:

***SPLUNK*** sourcetype=YourSourcetype index=YourIndex host=foo1 ...

And Splunk will index your file with those parameters.

Read more about it in the Splunk docs: http://www.splunk.com/base/Documentation/4.1.5/Admin/Assignmetadatatoeventsdynamically

I use the built-in sinkhole when I am doing a quick test of a new log-type to evaluate it before setting up a perm monitor or when doing an investigation and I need to get a bunch of evidence into Splunk from a system that wasn't already monitored by Splunk.

0 Karma

hexx
Splunk Employee
Splunk Employee

If you intend to index the file instead of having Splunk monitoring/tailing it, then I think the CLI "oneshot" command is indeed the best solution.

# splunk add oneshot <path_to_your_file>

You could also create a new monitor input for that file from the CLI, this will index your file but it won't be at all the same than "uploading" it to Splunk as a one-time thing, as Splunk will be keeping track of it.

# splunk add monitor <path_to_your_file>

Another possibility is to toss the file in $SPLUNK_HOME/var/spool/splunk which is set up by default as a batch input (see $SPLUNK_HOME/etc/system/default/inputs.conf). Note that the file will be indexed destructively, so you may want to copy it there, not move it.

Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas     Cisco Live 2026 is almost here, and this ...

What Is the Name of the USB Key Inserted by Bob Smith? (BOTS Hint, Not the Answer)

Hello Splunkers,   So you searched, “what is the name of the usb key inserted by bob smith?”  Not gonna lie… ...

Automating Threat Operations and Threat Hunting with Recorded Future

    Automating Threat Operations and Threat Hunting with Recorded Future June 29, 2026 | Register   Is your ...