Splunk Search

Splunk HF exports logs using a CLI command as a Linux crontab?

sarvananth
Explorer

I'm new to Splunk Enterprise, and my task is to forward logs from Splunk HF (AWS EC2 instance) to an AWS Cloud Watch log group.

I tried to export the logs using CLI commands and stored them on the Splunk HF server locally. Then, I used the Cloud Watch agent to send the logs to the Cloud Watch log group.

please refer the below Splunk cli command for export the logs

#./splunk search "index::***** sourcetype::linux_audit" -output rawdata -maxout 0 -max_time 5 -auth splunk:***** >> /opt/linux-Test01.log

The challenge I'm facing is that when I run the CLI command using a Linux crontab, it does not export the logs.

Are there any other solutions or guidance available to resolve this issue?

0 Karma
1 Solution

isoutamo
SplunkTrust
SplunkTrust

Hi

when you are running commands from cron, you must remember that there is no sourced environments. Usually you should use some wrapped script to:

  1. source your user's shell environment including env vars + etc.
  2. run your commands / scripts with full paths!

In your case this means e.g.

#!/bin/bash
source ~<your user>/.bash_login
source ~<your user>/.bashrc
cd <where ever you thing you should be>
/opt/splunk/bin/splunk .....

Of course you should add needed error checks after commands etc.

r. Ismo 

View solution in original post

isoutamo
SplunkTrust
SplunkTrust

Hi

when you are running commands from cron, you must remember that there is no sourced environments. Usually you should use some wrapped script to:

  1. source your user's shell environment including env vars + etc.
  2. run your commands / scripts with full paths!

In your case this means e.g.

#!/bin/bash
source ~<your user>/.bash_login
source ~<your user>/.bashrc
cd <where ever you thing you should be>
/opt/splunk/bin/splunk .....

Of course you should add needed error checks after commands etc.

r. Ismo 

sarvananth
Explorer

Hi R.Ismo,

 

yes, it is working fine, and thank you very much for your help.
Is it possible to export the logs last 5 minutes using a CLI command?

 

 

0 Karma

isoutamo
SplunkTrust
SplunkTrust

Basically just …/splunk search ….just check correct syntax from docs. Thera are also defined output format etc. you should remember that some events could come later, so if you just export all events from last 5min you probably miss some….

0 Karma
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!

Index This | What travels the world but is also stuck in place?

April 2026 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Discover New Use Cases: Unlock Greater Value from Your Existing Splunk Data

Realizing the full potential of your Splunk investment requires more than just understanding current usage; it ...

Continue Your Journey: Join Session 2 of the Data Management and Federation Bootcamp ...

As data volumes continue to grow and environments become more distributed, managing and optimizing data ...