Skip to main content

Exec

Execute a command directly without a shell interpreter. Arguments are passed to the executable as-is, without shell expansion or interpretation.

$ osapi client node command exec --command ls --args "-la,/tmp"

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

HOSTNAME STATUS EXIT STDOUT
web-01 ok 0 total 8 drwxrwxrwt 10 root r...

1 host: 1 ok

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

Execute a command in a specific working directory with a custom timeout:

$ osapi client node command exec \
--command cat \
--args "config.yaml" \
--cwd /etc/osapi \
--timeout 10

Target by label to execute on a group of servers:

$ osapi client node command exec --command whoami --target group:web

Use @fact.* references to inject live system values. Each agent resolves its own facts, so this works correctly with broadcast targeting:

$ osapi client node command exec \
--command ip --args "addr,show,dev,@fact.interface.primary" \
--target _all

See System Facts for all available @fact.* references.

JSON Output

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

$ osapi client node command exec --command hostname --json

Raw Output

Use --stdout to print only the remote command's stdout, without the table wrapper:

$ osapi client node command exec --command ls --args "-la" --stdout
total 48
drwxr-xr-x 12 john staff 384 Mar 2 10:00 .
-rw-r--r-- 1 john staff 1234 Mar 2 09:30 main.go

Use --stderr to print only stderr:

$ osapi client node command exec --command ls --args "/nonexistent" --stderr
ls: cannot access '/nonexistent': No such file or directory

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

$ osapi client node command exec --command hostname --target _all --stdout
[web-01] web-01.example.com
[web-02] web-02.example.com

The CLI exit code matches the remote command's exit code, making it scriptable:

$ osapi client node command exec --command "test" --args "-f,/etc/hosts" --stdout && echo exists
exists

Flags

FlagDescriptionDefault
--commandThe command to execute (required)
--argsCommand arguments (comma-separated)[]
--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