script
Description
Calls an external python program that can modify or generate search results.
- Splunk Cloud Platform
- You must create a private app that contains your custom script. If you are a Splunk Cloud administrator with experience creating private apps, see Manage private apps in your Splunk Cloud Platform deployment in the Splunk Cloud Admin Manual. If you have not created private apps, contact your Splunk account representative for help with this customization.
- Splunk Enterprise
- Scripts must be declared in the commands.conf file and be located in the $SPLUNK_HOME/etc/apps/<app_name>/bin/ directory. The script is executed using $SPLUNK_HOME/bin/python.
This command is considered risky because, if used incorrectly, it can pose a security risk or potentially lose data when it runs. As a result, this command triggers SPL safeguards. See SPL safeguards for risky commands in Securing the Splunk Platform.
Syntax
script <script-name> [<script-arg>...] [maxinputs=<int>]
Required arguments
- script-name
- Syntax: <string>
- Description: The name of the scripted search command to run, as defined in the commands.conf file.
Optional arguments
- maxinputs
- Syntax: maxinputs=<int>
- Description: Specifies how many of the input results are passed to the script per invocation of the command. The
script
command is invoked repeatedly in increments according to themaxinputs
argument until the search is complete and all of the results have been displayed. Do not change the value ofmaxinputs
unless you know what you are doing. - Default: 50000
- script-arg
- Syntax: <string> ...
- Description: One or more arguments to pass to the script. If you are passing multiple arguments, delimit each argument with a space.
Usage
The script
command is effectively an alternative way to invoke custom search commands.
See Create custom search commands for apps in Splunk Cloud Platform or Splunk Enterprise in the Developer Guide on the Developer Portal.
The following search:
| script commandname
is the same as this search:
| commandname
Some functions of the script command have been removed over time. The explicit choice of Perl or Python as an argument is no longer functional and such an argument is ignored. If you need to write Perl search commands, you must declare them as Perl in the commands.conf file. This is not recommended, as you need to determine a number of underdocumented things about the input and output formats. Additionally, support for the etc/searchscripts directory has been removed. Search commands must be located in the bin directory of an app in your Splunk deployment. For more information about creating custom search commands for apps in Splunk Cloud Platform or Splunk Enterprise, see the Developer Guide for Splunk Cloud Platform and Splunk Enterprise.
Examples
Example 1:
Run the Python script "myscript" with arguments, myarg1 and myarg2; then, email the results.
... | script myscript myarg1 myarg2 | sendemail to=david@splunk.com
savedsearch | scrub |
This documentation applies to the following versions of Splunk® Enterprise: 8.1.0, 8.1.1, 8.1.2, 8.1.3, 8.1.4, 8.1.5, 8.1.6, 8.1.7, 8.1.8, 8.1.9, 8.1.10, 8.1.11, 8.1.12, 8.1.13, 8.1.14, 8.2.0, 8.2.1, 8.2.2, 8.2.3, 8.2.4, 8.2.5, 8.2.6, 8.2.7, 8.2.8, 8.2.9, 8.2.10, 8.2.11, 8.2.12, 9.0.0, 9.0.1, 9.0.2, 9.0.3, 9.0.4, 9.0.5, 9.0.6, 9.0.7, 9.0.8, 9.0.9, 9.0.10, 9.1.0, 9.1.1, 9.1.2, 9.1.3, 9.1.4, 9.1.5, 9.2.0, 9.2.2, 9.2.1, 9.3.0
Feedback submitted, thanks!