Skip to content

rvrdata.adapters.script

Adapter for executing shell scripts and CLI commands.

class RvrdataScript

Adapter for executing shell scripts and CLI commands.

run()

Run script as subprocess.

  • Parameters:
  • cli (str) – Command to run
  • cwd (str) – Current working directory path to use (defaults to None, e.g. on rover, this is /home/rover)
  • log_cli (bool) – Log runtime command as an INFO level log message (defaults to False)
  • show_cli (bool) – Outputs command to stdout (and enables logging cli) Show and log CLI are disabled by default. Care should be taken enabling them since runtime commands may contain sensitive information.
  • shell (bool) – Runs script in shell (defaults to /bin/sh on POSIX)
  • silent (bool) – hides script output from stdout (defaults to False)
  • strip_newline (bool) – removes trailing carriage return (defaults to False)
  • timeout (int) – Number of seconds script is allowed to run (defaults to 300s)
  • Returns: success=True if the script exit code is 0

The console output of the script is appended to the step as .data.

Example: Dataflow running a command

steps:
  - name: get_sys_date
    notes: Set `steps.get_sys_date.data` to current system time.
    action: script.run
    params:
        cli: date
        strip_newline: True

Example: Dataflow running a command in alternate shell

steps:
  - name: run_bash_script
    notes: Alternate shells can be used instead of /bin/sh.
    action: script.run
    params:
        cli:
          - "/bin/bash"
          - "-c"
          - "echo $0"

Example: Dataflow running a command quietly

steps:
  - name: get_recent_rvrdata_log
    notes: Use silent option to avoid dumping output to console.
    action: script.run
    params:
        cli: |
            tail -1000 logs/rvrdata.log
        silent: True

Example: Showing runtime CLI in stdout

variables:
    msg: "{{ kwargs.msg|default('DEFAULT_MSG', true) }}"
steps:
  - name: show_cli
    notes: Shows runtime command
    action: script.run
    params:
        cli: |
            echo "{{ msg }}"
        show_cli: True

Example: Showing runtime CLI in log

steps:
  - name: log_cli
    notes: Shows runtime command in log when log level set to INFO
    action: script.run
    params:
        cli: |
            echo "CAREFUL: cli may include sensitive info such as passwords"
        log_cli: True

Run Metrics

The following metrics are included in the step results:

  • rvrdata.dataflow.action.script.run.size: The size of stdout in bytes (int).
  • rvrdata.dataflow.action.script.run.line_count: Number of newlines in stdout (int).

One row is added to the metrics each time the action is run.

force_pass()

Fake successful action that does nothing.

See force_pass in stdout adapter.