Skip to main content

Shell

Execute a command through /bin/sh -c. Supports shell features like pipes, redirects, and variable expansion.

$ osapi client node command shell --command "ls -la /tmp | grep log"

Job ID: 550e8400-e29b-41d4-a716-446655440000

HOSTNAME STATUS EXIT STDOUT
web-01 ok 0 -rw-r--r-- 1 root root 4096 ...

1 host: 1 ok

Long output is truncated in the table view. Use --json for the full response data.

Use shell syntax like pipes and redirects:

$ osapi client node command shell \
--command "df -h / | tail -1 | awk '{print \$5}'" \
--timeout 10

Execute in a specific working directory:

$ osapi client node command shell \
--command "cat *.conf | wc -l" \
--cwd /etc

Target by label to execute on a group of servers:

$ osapi client node command shell \
--command "systemctl is-active nginx" \
--target group:web

JSON Output

Use --json to get the full untruncated API response:

$ osapi client node command shell --command "uname -r" --json

Raw Output

Use --stdout to print only the remote command's stdout:

$ osapi client node command shell --command "df -h / | tail -1" --stdout
/dev/sda1 50G 12G 35G 26% /

Use --stderr to print only stderr:

$ osapi client node command shell --command "cat /nonexistent" --stderr
cat: /nonexistent: No such file or directory

Both flags can be combined. Each line is prefixed with the hostname:

$ osapi client node command shell --command "uname -r" --target _all --stdout
[web-01] 5.15.0-91-generic
[web-02] 5.15.0-91-generic

The CLI exit code matches the remote command's exit code.

Flags

FlagDescriptionDefault
--commandThe shell command to execute (required)
--cwdWorking directory for the command
--timeoutTimeout in seconds (max 300)30
-T, --targetTarget: _any, _all, hostname, or label (group:web)_all
--stdoutPrint only remote stdout
--stderrPrint only remote stderr
-j, --jsonOutput raw JSON response