<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: scripted input does not produce same results as running script manually in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/scripted-input-does-not-produce-same-results-as-running-script/m-p/368966#M6015</link>
    <description>&lt;P&gt;Refer to a &lt;A href="https://answers.splunk.com/answers/418398/how-to-get-splunk-to-run-my-python-shell-script.html"&gt;previous answers post&lt;/A&gt; in regards to testing your script with the same environment that will be used when the script is run for your input.&lt;/P&gt;

&lt;P&gt;It's likely that your runtime environment looks different when you're running it manually to test and when it's run by Splunk.&lt;/P&gt;</description>
    <pubDate>Sun, 31 Dec 2017 17:28:30 GMT</pubDate>
    <dc:creator>micahkemp</dc:creator>
    <dc:date>2017-12-31T17:28:30Z</dc:date>
    <item>
      <title>scripted input does not produce same results as running script manually</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/scripted-input-does-not-produce-same-results-as-running-script/m-p/368964#M6013</link>
      <description>&lt;P&gt;I have a python script that queries a mongo database and pulls all the results since the last time the script ran. it then stores the date of the last event it pulled to a text file to reference later. When I run this script manually it works exactly as intended. When it runs through Splunk it never creates the text document that contains the last date pulled and for some reason it only returns the last document when it should return multiple events. &lt;/P&gt;

&lt;P&gt;my configuration is as follows: &lt;/P&gt;

&lt;P&gt;inputs.conf&lt;BR /&gt;
[script://$SPLUNK_HOME/etc/apps/xdrip_mongo/bin/entries.py]&lt;BR /&gt;
disabled = false&lt;BR /&gt;
interval = 30&lt;BR /&gt;
source = xdrip&lt;BR /&gt;
sourcetype = mellitus_entry&lt;/P&gt;

&lt;P&gt;props.conf &lt;BR /&gt;
[mellitus_entry]&lt;BR /&gt;
SHOULD_LINEMERGE = false&lt;/P&gt;

&lt;P&gt;and the relevant portion of python: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;try:
    f_lastDate = open('lastDate.txt', 'r')
    s_lastDate = f_lastDate.read()
    try:
        int_lastDate = int(s_lastDate)
    except ValueError:
        int_lastDate = 0
except IOError:
    int_lastDate = 0
    s_lastDate = str(int_lastDate)
f_lastDate = open('lastDate.txt', 'w')

for doc_entry in entries.find({'date': {"$gt": int_lastDate}}):
    print "_id = %s, date = %s, dateString = %s, device = %s," \
          "direction = %s, filtered = %s, noise = %s, rssi = %s," \
          "sgv = %s, type = %s, unfiltered = %s" % \
            (doc_entry['_id'],
                doc_entry['date'],
                doc_entry['dateString'],
                doc_entry['device'],
                doc_entry['direction'],
                doc_entry['filtered'],
                doc_entry['noise'],
                doc_entry['rssi'],
                doc_entry['sgv'],
                doc_entry['type'],
                doc_entry['unfiltered'])

    s_lastDate = str(doc_entry['date'])

f_lastDate.write(s_lastDate)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 17:27:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/scripted-input-does-not-produce-same-results-as-running-script/m-p/368964#M6013</guid>
      <dc:creator>bkwoka</dc:creator>
      <dc:date>2020-09-29T17:27:50Z</dc:date>
    </item>
    <item>
      <title>Re: scripted input does not produce same results as running script manually</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/scripted-input-does-not-produce-same-results-as-running-script/m-p/368965#M6014</link>
      <description>&lt;P&gt;I figured it out. The script is running with system32 as the working directory. I assumed it would be running in the /bin of the app. Once I hardcoded the absolute path it worked. &lt;/P&gt;</description>
      <pubDate>Sun, 31 Dec 2017 16:00:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/scripted-input-does-not-produce-same-results-as-running-script/m-p/368965#M6014</guid>
      <dc:creator>bkwoka</dc:creator>
      <dc:date>2017-12-31T16:00:24Z</dc:date>
    </item>
    <item>
      <title>Re: scripted input does not produce same results as running script manually</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/scripted-input-does-not-produce-same-results-as-running-script/m-p/368966#M6015</link>
      <description>&lt;P&gt;Refer to a &lt;A href="https://answers.splunk.com/answers/418398/how-to-get-splunk-to-run-my-python-shell-script.html"&gt;previous answers post&lt;/A&gt; in regards to testing your script with the same environment that will be used when the script is run for your input.&lt;/P&gt;

&lt;P&gt;It's likely that your runtime environment looks different when you're running it manually to test and when it's run by Splunk.&lt;/P&gt;</description>
      <pubDate>Sun, 31 Dec 2017 17:28:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/scripted-input-does-not-produce-same-results-as-running-script/m-p/368966#M6015</guid>
      <dc:creator>micahkemp</dc:creator>
      <dc:date>2017-12-31T17:28:30Z</dc:date>
    </item>
  </channel>
</rss>

