Splunk Dev

Can you help me with a script command to generate or show output on Splunk search head screen?

manish_traf
Engager

hello splunkers ,

I got stuck in one problem please help

I have created one script provided below :

#!/opt/splunk/bin/python2.7

f = open('/opt/splunk/etc/apps/search/bin/hello.txt','a')
f.write("my name is manish")
f.write('\n')
f.close()

which I will log an string in TXT file.

But, I want to see the output on the Splunk screen.

I have added the hello command in commands.conf.

I'm able to run the query | script hello. But, I'm not seeing the output in the Splunk screen, even though I have used print statement in Python script, but it's not helping.

Please help

Thanks
Manish Kumar

0 Karma
1 Solution

manish_traf
Engager

No problem dear splunkers ,

I have figured it on my own

For this all we just need to write one python script and mention that script name in commands.conf
and for printing the output to splunk screen we need to import Intersplunk.py and use the outputresults method of it

#!/opt/splunk/bin/python2.7


import sys
sys.path.insert(0,'/opt/splunk/lib/python2.7/site-packages/splunk/')

import Intersplunk as man


result = []

results = {
"Name": "Manish"

}

result.append(results)

man.outputResults(result)

f = open('hello.txt','a')
f.write(str(result))
f.write('\n')
f.close()

View solution in original post

0 Karma

manish_traf
Engager

No problem dear splunkers ,

I have figured it on my own

For this all we just need to write one python script and mention that script name in commands.conf
and for printing the output to splunk screen we need to import Intersplunk.py and use the outputresults method of it

#!/opt/splunk/bin/python2.7


import sys
sys.path.insert(0,'/opt/splunk/lib/python2.7/site-packages/splunk/')

import Intersplunk as man


result = []

results = {
"Name": "Manish"

}

result.append(results)

man.outputResults(result)

f = open('hello.txt','a')
f.write(str(result))
f.write('\n')
f.close()
0 Karma
Get Updates on the Splunk Community!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...