Shell
Defining a 'shell' job module in your grace.yml to execute local shell commands or scripts.
The shell job module allows you to execute arbitrary commands or scripts directly on the local machine where the Grace CLI is running. This is extremely useful for integrating non-mainframe tasks into your workflow, such as:
- Pre-processing data before uploading to z/OS.
- Post-processing data downloaded from z/OS.
- Interacting with cloud services (e.g., AWS CLI, Azure CLI,
gcloud). - Running custom scripts (Python, Node.js, Bash, etc.) as part of the pipeline.
- Calling other CLI tools.
Shell jobs are executed by the Grace instance itself, not submitted to z/OS.
An example shell script using Grace exposed input/output environment variables:
See Virtual Paths & Job I/O,
inputs, andoutputsfor more information on how to use this.
While shell jobs use common job fields like name, depends_on, inputs, and outputs - the type and with block are central to its definition.
type
- Value:
shell(Required) - Description: Identifies this job as a local shell execution task. Grace will use its internal
ShellHandlerto manage execution.
with (Required)
The with block is required for shell jobs and specifies the command or script to be executed. It contains one of the following: inline or script.
with.inline
- Type:
String(can be a multi-line string using|) - Description: A string containing the shell commands to be executed directly. Multiple commands can be separated by newlines or semicolons as per standard shell syntax.
- Example (single line):
- Example (multi-line):
with.script
- Type:
String - Description: The path to a script file to be executed.
- The path can be relative to
grace.yml(e.g.scripts/my_task.sh) - It can also use the
src://prefix (e.g.src://myscript.sh) to refer to a script within thesrc/directory of your Grace workspace. Ifsrc://is used, Grace resolves it to the local path; it does not upload the script to run on the mainframe for ashelljob.
- The path can be relative to
- Example:
with.shell (Optional)
- Type:
String - Default:
sh(or the system's default shell interpreter) - Description: Specifies the shell interpreter to use for executing
inlinecommands or thescriptfile.- Common values:
sh,bash,zsh,python3,node, etc. - If executing a script file (e.g.
.py,.js) that has a shebang (e.g.#!/usr/bin/env python3), the shebang will typically take precedence ifwith.shellis not specified or is a generic shell likesh. Providingwith.shell: python3is recommended to make the intent explicit.
- Common values:
- Example:
Important: You must provide either
with.inlineorwith.script, but not both.
inputs
- Description: Defines data inputs for the shell job. For each input, Grace exposes an environment variable to your script/commands giving the local path to the data.
- Environment variable convention:
GRACE_INPUT_<NAME_IN_UPPERCASE>- e.g. An input with
name: CONFIG_FILEwill be available as$GRACE_INPUT_CONFIG_FILE
- e.g. An input with
- Behavior:
- If the
pathiszos://orzos-temp://, Grace downloads the dataset/member to a temporary local staging file, and the environment variable points to this downloaded copy. - You can control the download mode using the optional
encodingfield within the input definition. - If the
pathisfile://orsrc://, the environment variable points directly to that resolved local file.
- If the
- Your script should use these environment variables to access input files:
See Virtual Paths & Job I/O for details on
pathprefixes and Grace exposed environment variables.
outputs
- Description: Defines files your shell job is expected to produce. For each output, Grace provides an environment variable to your script/commands. This represents the local path where your script MUST write the output file.
Think of this like a contract by your shell job that indicates which resources will be produced for jobs downstream or will reside in the specified locations.
- Environment variable convention:
GRACE_OUTPUT_<NAME_IN_UPPERCASE>- Example: An output with
name: REPORT_DATAmeans your script should write to$GRACE_OUTPUT_REPORT_DATA.
- Example: An output with
- Behavior:
- Grace determines the appropriate local path for the output based on its
pathdefinition (e.g., directly forfile://, or a path in a local staging area forlocal-temp://,zos://, andzos-temp://). - Your script MUST create and write its output to the file path given by this environment variable.
- If the output
pathiszos://orzos-temp://, Grace will automatically upload the local file (written by your script to$GRACE_OUTPUT_...) to the specified dataset after the script completes successfully.
- Grace determines the appropriate local path for the output based on its
- Example script usage:
See Virtual Paths & Job I/O for more on
pathprefixes and Grace exposed environment variables.
Execution environment
- Working directory: Shell commands/scripts execute with the
grace.ymldirectory as their working directory. - Environment variables: Inherits Grace CLI's environment, plus the
GRACE_INPUT_*andGRACE_OUTPUT_*variables.
Behavior notes
- Local execution: All operations occur on the machine where
graceis run. - Error handling: Non-zero exit codes from scripts/commands cause the job to fail. Failures during input download or output upload also cause job failure.
- Stdout/stderr: Captured and available in the job's JSON logfile under
.grace/logs/.
The shell job module provides powerful flexibility to integrate local processing and interactions with external systems directly into your Grace workflows.