Getting Data In

Scripted Input Windows Batch - stdout not in the log

Matthias_BY
Communicator

Hello,

i have written a batch file within windows to get some data:

wget.exe -O status.txt http://192.168.178.XXX/SSI/supply_status_info.htm 
"C:\Program Files (x86)\GnuWin32\bin\grep.exe" -A 1 "%1" status.txt

If i saved the file as batch. if i run the file on the cmd mode with a parameter i get the output i want:

C:\Program Files\Splunk\bin\scripts>inputs-cartridge.bat "Black Print Cartridge"
C:\Program Files\Splunk\bin\scripts>wget.exe -O status.txt http://192.168.178.XXX/SSI/supply_status_info.htm
--2013-07-05 11:19:48--  http://192.168.178.100/SSI/supply_status_info.htm
Connecting to 192.168.178.100:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: `status.txt'

    [  <=>                                  ] 25,938       107K/s   in 0.2s

2013-07-05 11:19:48 (107 KB/s) - `status.txt' saved [25938] 
C:\Program Files\Splunk\bin\scripts>"C:\Program Files (x86)\GnuWin32\bin\grep.ex
e" -A 1 ""Black Print Cartridge"" status.txt
grep: Print: No such file or directory
grep: Cartridge: No such file or directory
status.txt:                      <td><img src="/Images/Black_Toner.gif" > </td>
status.txt-                    </tr>
--
status.txt:                <td valign="top"><font class="clf"> **Black Print Cartr
idge**<br>Order HP Part:&nbsp;&nbsp;Q6000A</font></td>
status.txt-                <td valign="top"><font class="clf">**73%**<br></font> </t
d>

If i configure the scripted input within splunk - i only get the command line commands and not the output of the scripts... what did i wrong?

05.07.13 11:21:47,000   
C:\Windows\system32>wget.exe -O status.txt http://192.168.178.100/SSI/supply_status_info.htm  
C:\Windows\system32>"C:\Program Files (x86)\GnuWin32\bin\grep.exe" -A 1 ""Black Print Cartridge"" status.txt 
Tags (2)
0 Karma
1 Solution

Matthias_BY
Communicator

Found the Error.

My first command did not work - i did have copied the wget.exe in the bin/scripts directory. So it was working fine as i tested it manually. But as splunk called it it seems that maybe it's called from a different location and wget.exe was not found.

i copied wget.exe into my system32 folder to make sure all requests can reach it.

now i get the expected output.

View solution in original post

0 Karma

Matthias_BY
Communicator

Found the Error.

My first command did not work - i did have copied the wget.exe in the bin/scripts directory. So it was working fine as i tested it manually. But as splunk called it it seems that maybe it's called from a different location and wget.exe was not found.

i copied wget.exe into my system32 folder to make sure all requests can reach it.

now i get the expected output.

0 Karma

krugger
Communicator

I would suggest you change you batch file to:

@ECHO OFF
wget.exe -O status.txt http://192.168.178.XXX/SSI/supply_status_info.htm 
"C:\Program Files (x86)\GnuWin32\bin\grep.exe" -A 1 %1 status.txt

I removed echo of commands to the command line and fixed you grep which isn't working as intended, because you are grepping for Black instead of your string.

krugger
Communicator

Splunk requires the batch file to be in the $SPLUNK_HOME/bin/scripts directory.

Had forgotten about that.

0 Karma

Matthias_BY
Communicator

thanks for your response - i changed it - but now no data coming in. if i add echo "Hello World" i can see it in Splunk - so Splunk calls the script... but the batch file still does not output the proper content i want.

0 Karma
Get Updates on the Splunk Community!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Wondering How to Build Resiliency in the Cloud?

IT leaders are choosing Splunk Cloud as an ideal cloud transformation platform to drive business resilience,  ...

Updated Data Management and AWS GDI Inventory in Splunk Observability

We’re making some changes to Data Management and Infrastructure Inventory for AWS. The Data Management page, ...