Getting Data In

How to create a scheduled search to export results as a CSV file to an external share?

andrei_radu
New Member

Hello,

I need to create a scheduled search on a search head and automatically export the results as a .csv file, then copy the file to an external share that is mapped to my Splunk server (Linux).

I was trying to use CLI splunk search. Ran the command:

splunk search "search string" > -format csv > /myshare/file_name.csv

This works super fine, can be added to crontab, but the problem is that it requires authentication. If I manually authenticate for the first time then add the search into crontab, it will ask for credentials again?

Otherwise, can you suggest any other methods of automatically exporting search results into a file, then copy a file to an external share?

Thanks a lot!

0 Karma

anantdeshpande
Path Finder

Do you have solution now?

0 Karma

somesoni2
SplunkTrust
SplunkTrust

Try like this

1) Add command ...| outputcsv to your search. This will export the search results to location $SPLUNK_HOME/var/run/splunk/csv
https://docs.splunk.com/Documentation/Splunk/6.4.2/SearchReference/Outputcsv

2)Save your search as scheduled saved search and run it at your convenient cron schedule

3) Configure this saved search to run a script as the alert action (alert condition always).

4) Create script (which will run as part of alert action) to copy the exported file from $SPLUNK_HOME/var/run/splunk/csv to your external share.

deva1995
Explorer

Can anyone share the script for copying the file to external server?

0 Karma

mayankm21
New Member

Did you implement this? Can you please share the script? 

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