Getting Data In
Highlighted

Scripted Input Windows Batch - stdout not in the log

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
Highlighted

Re: Scripted Input Windows Batch - stdout not in the log

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.

Highlighted

Re: Scripted Input Windows Batch - stdout not in the log

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
Highlighted

Re: Scripted Input Windows Batch - stdout not in the log

Communicator

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

Had forgotten about that.

0 Karma
Highlighted

Re: Scripted Input Windows Batch - stdout not in the log

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