Shell Script
Overview
The ShellScriptWorkEntryExecutor class runs a shell script, allowing actions to be performed at the operating system level from a Task.
Returning a non-zero exit code from the shell script will result in an error.
Java properties
You can specify the permitted scripts to be executed by configuring the following properties in the ria-boot.properties file:
com.ria.dih.core.shell.scriptDir— specifies the default directory for the shell scripts.com.ria.dih.core.shell.taskDirAllowed— enables you to override the default directory by specifying it in the Task. Set this tofalseto only allow scripts located in the directory specified in the com.ria.converter.shell.scriptDir property.
If com.ria.dih.core.shell.scriptDir is not specified and com.ria.dih.core.shell.taskDirAllowed is false, no shell scripts may be executed.
Base parameters
The following parameters can be specified on a shell script task:
| Parameter | Description |
|---|---|
scriptDir | Specifies the directory where the scripts are located. It can only be specified in the Task if the com.ria.dih.core.shell.taskDirAllowed property is set to true. |
scriptCmd | Specifies the name of the script to execute, followed by any script-specific parameters. The script name cannot include any relative path references to execute scripts in other directories. For example, ../my-script.sh p1 p2 is invalid because of the ../ path reference in the name. |
Custom parameters
The scriptCmd parameter can pass parameters to a script in a command-line fashion. For example, the following is a valid script in which parm1 and parm2 will be passed to the script as parameters $1 and $2.
my-custom-bash-script.sh parm1 parm2
To send variable values to a script, you can use custom parameters. These custom parameters will be set as environment variables for the shell script to access.
The environment variables are prefixed by T, which stands for Task parameter, followed by the name of the custom parameter. For example, let’s assume that this is a custom parameter specified in the Task:
customGreeting = Hello from DIH
Inside the shell script, this value can be accessed through the $_T_customGreeting variable , for example:
#!/bin/bash
echo My custom greeting is $_T_customGreeting
Internal variables
DIH environmental variables, such as the job name, run id, etc., can be retrieved through environmental variables prefixed by I, followed by the name of the variable in uppercase. The following are the supported variables:
_I_JOB_NAME_I_RUN_ID_I_RUN_SEQ_I_TASK_ID_I_TARGET_ID_I_MAPPING_SEQ_I_THREAD_NUMBER_I_THREAD_COUNT_I_CURRENT_DATE_I_CURRENT_TIME_I_CURRENT_DATE_TIME_I_CURRENT_TIMESTAMP