Getting Data In

how to count the number of files and directories in a folder in splunk

Afef
Communicator

Hi,
Please Could someone tell me how to count the number of files and directories in a folder in splunk ?
Regards

Tags (2)
0 Karma

martin_mueller
SplunkTrust
SplunkTrust

You could create a script that computes the counts you're looking for, a naïve one-liner counting the files and directories in a path could be this:

cd /path/to/count; date; pwd; ls | wc -l

Then configure that as a scripted input in your Splunk.

martin_mueller
SplunkTrust
SplunkTrust

I'm sure similar things can be done with PowerShell. A quick googling suggests something like this: http://stackoverflow.com/questions/14714284/count-items-in-a-folder-with-powershell

0 Karma

Afef
Communicator

Thank you martin, but i'm working with windows not linux, so what should i do ?

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

Sure. Say you saved my one-liner or your much better script to $SPLUNK_HOME/etc/apps/your_app/bin/dircount.sh, then you can define this in inputs.conf:

[script://$SPLUNK_HOME/etc/apps/your_app/bin/dircount.sh]
index = your_index
sourcetype = your_sourcetype
interval = number of seconds between runs

You can also configure this through the UI if run on a Searchhead, Indexer, or Heavy Forwarder by going to Settings -> Data Inputs -> Scripts -> New.

Find the docs here: http://docs.splunk.com/Documentation/Splunk/6.1.3/Data/Setupcustominputs

0 Karma

smudge797
Path Finder

Can you expand on the "Then configure that as a scripted input in your Splunk." Thanks!

0 Karma

Afef
Communicator

I want just to calculate the number of directories and files in a specific folder ! so if it is possible to not index data it will be good. If not i want to have the count and create a dashboard like that :

DIRECTORY NumberOfFiles NumberOfDirectories
Dir Name NBFiles NBDir

So How could i do this ?

Regards

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

Are you trying to index that count for some directory, or are you trying to calculate statistics based on already indexed data and the path in their source field?

0 Karma
Get Updates on the Splunk Community!

Fueling your curiosity with new Splunk ILT and eLearning courses

At Splunk Education, we’re driven by curiosity—both ours and yours! That’s why we’re committed to delivering ...

Splunk AI Assistant for SPL 1.1.0 | Now Personalized to Your Environment for Greater ...

Splunk AI Assistant for SPL has transformed how users interact with Splunk, making it easier than ever to ...

Unleash Unified Security and Observability with Splunk Cloud Platform

     Now Available on Microsoft AzureOn Demand Now Step boldly into the AI revolution with enhanced security ...