Skip to main content
Version: 3.5.3

Input: exec

Execute arbitrary commands

Some things to take note of:

  • Shell expansion ($VAR) will take place using the Pipe environment
  • Will usually wrap the output as JSON in the form {"_raw":...}
  • Any linefeeds will be removed from the command, so this works fine:
    exec:
    command: |
    docker ps
    -all
    --no-trunc
    --quiet
    --size

Field Summary

Field NameTypeDescriptionDefault
whenmessage_filterFire this input when a specific internal message occurs-
intervaldurationHow often to run the command-
croncronHow often to run the command. Note that unlike standard Cron, Pipes use a Cron syntax that includes a column for seconds. See full discussion-
immediateboolRun as soon as invoked, instead of waiting for the specified cron intervalfalse
random-offsetdurationSets a random offset to the schedule, then sticks to it0s
windowWindowFor resources that need a time window to be specified-
blockboolBlock further input schedules from triggering if the pipe output is retryingfalse
retryRetryFor operations that could potentially fail-
commandstringA shell command to be executed-
batchBatchFor when a number of output events need to be marked as belonging to a distinct group-
resultExecResultOffers a way to collect the full output of a command: stdout, stdin, and exit status-
rawboolDo not wrap incoming data in JSON format (i.e. `{"_raw":"some data"})false
countintegerNumber of times to run the command-
no-strip-linefeedsboolDo not strip newline characters (\n) automatically on multi-line commandsfalse
ignore-line-breaksboolDo not treat separate output lines as distinct eventsfalse
envpathAccepts a YAML file containing variables that would be added to environment of the command-

Fields

when

Type: message_filter

Fire this input when a specific internal message occurs

This field overloads time-based scheduling with a scheduler that fires on matching messages.

Example

Pipe Language Snippet:

input:
http-poll:
when:
message-received:
filter-type:
- pipe-idle
url: "http://localhost:8888"
raw: true
ignore-line-breaks: true

interval

Type: duration

How often to run the command

By default, interval: 0s which means: once. Note that scheduled inputs set document markers. See full discussion

Example

Pipe Language Snippet:

exec:
command: echo 'once a day'
interval: 1d

cron

Type: cron

How often to run the command. Note that unlike standard Cron, Pipes use a Cron syntax that includes a column for seconds. See full discussion

Example: Once a day

Pipe Language Snippet:

exec:
command: echo 'once a day'
cron: '0 0 0 * * *'

Example: Once a day, using a convenient shortcut

Pipe Language Snippet:

exec:
command: echo 'once a day'
cron: '@daily'

immediate

Type: bool

Default: false

Run as soon as invoked, instead of waiting for the specified cron interval

Example: Run immediately on invocation, and thereafter at 10h every morning

Pipe Language Snippet:

exec:
command: echo 'hello'
immediate: true
cron: '0 0 10 * * *'

random-offset

Type: duration

Default: 0s

Sets a random offset to the schedule, then sticks to it

This can help avoid the thundering herd problem, where you do not, for example, want to overload some service at 00:00:00

Example: Would fire up to a minute after every hour

Pipe Language Snippet:

exec:
command: echo 'hello'
random-offset: 1m
cron: '0 0 * * * *'

window

Type: Window

For resources that need a time window to be specified

Field NameTypeDescriptionDefault
sizedurationWindow size-
offsetdurationWindow offset0s
start-timetimeAllows the windowing to start at a specified time-
highwatermark-filepathSpecify file where timestamp would be stored in order to resume, for when Pipe has been restarted-

  size

Type: duration

Window size

Example

Pipe Language Snippet:

exec:
command: echo 'one two'
window:
size: 1m

  offset

Type: duration

Default: 0s

Window offset

Example

Pipe Language Snippet:

exec:
command: echo 'one two'
window:
size: 1m
offset: 10s

  start-time

Type: time

Allows the windowing to start at a specified time

It should in the following format: 2019-07-10 18:45:00.000 +0200

Example

Pipe Language Snippet:

exec:
command: echo 'one two'
window:
size: 1m
start-time: 10s

  highwatermark-file

Type: path

Specify file where timestamp would be stored in order to resume, for when Pipe has been restarted

Example

Pipe Language Snippet:

exec:
command: echo 'one two'
window:
size: 1m
highwatermark-file:: /tmp/mark.txt

block

Type: bool

Default: false

Block further input schedules from triggering if the pipe output is retrying

retry

Type: Retry

For operations that could potentially fail

Field NameTypeDescriptionDefault
countintegerHow many attempts to make before declaring failure-
pausedurationHow long to pause before re-trying-
foreverboolKeep trying until success is declaredfalse

  count

Type: integer

How many attempts to make before declaring failure

Example

Pipe Language Snippet:

exec:
command: echo 'one two'
retry:
count: 1

Output:

{"_raw":"one two"}

  pause

Type: duration

How long to pause before re-trying

Accepts human-friendly formats, like 1m (for 1 minute) and 4h (for 4 hours)

Example

Pipe Language Snippet:

exec:
command: echo 'one two'
retry:
count: 6
pause: 10s

Output:

{"_raw":"one two"}

  forever

Type: bool

Default: false

Keep trying until success is declared

Accepts human-friendly formats, like 1m (for 1 minute) and 4h (for 4 hours)

Example

Pipe Language Snippet:

exec:
command: echo 'one two'
retry:
forever: true

Output:

{"_raw":"one two"}

command

Type: string

A shell command to be executed

Example

Pipe Language Snippet:

exec:
command: echo 'one two'

Output:

{"_raw":"one two"}

batch

Type: Batch

For when a number of output events need to be marked as belonging to a distinct group

Field NameTypeDescriptionDefault
uuid-fieldfieldField where generated uuid, the unique marker for the group, will be stored-
invocation-time-fieldfieldField where invocation time will be stored-
completion-time-fieldfieldField where completion (end of execution) time will be stored-
begin-marker-fieldfieldField used to mark first event in the group-
end-marker-fieldfieldField used to mark last event in the group-
line-count-fieldfieldField used to store the line count of the batch-
line-num-fieldfieldField used to store the line number of the batch-

  uuid-field

Type: field

Field where generated uuid, the unique marker for the group, will be stored

Example

Pipe Language Snippet:

exec:
command: |
for n in $(seq 3)
do
echo $n
done
no-strip-linefeeds: true
batch:
uuid-field: marker
interval: 1m

Output:

{"_raw":"foo","line-count":3,"line-num":1,"marker":"f3308aa9-6f56-4cc1-8782-c4231ff254b8"}
{"_raw":"2","line-count":3,"line-num":2,"marker":"f3308aa9-6f56-4cc1-8782-c4231ff254b8"}
{"_raw":"3","line-count":3,"line-num":3,"marker":"f3308aa9-6f56-4cc1-8782-c4231ff254b8"}

Example: For cases where event count is known, a simple counter is used, instead of uuid (useful for testing)

Pipe Language Snippet:

exec:
command: echo foo
no-strip-linefeeds: true
count: 3
batch:
uuid-field: marker
interval: 1m

Output:

{"_raw":"1","line-count":3,"line-num":1,"marker":"1"}
{"_raw":"2","line-count":3,"line-num":2,"marker":"1"}
{"_raw":"3","line-count":3,"line-num":3,"marker":"1"}
{"_raw":"1","line-count":3,"line-num":1,"marker":"2"}
{"_raw":"2","line-count":3,"line-num":2,"marker":"2"}
{"_raw":"3","line-count":3,"line-num":3,"marker":"2"}
{"_raw":"1","line-count":3,"line-num":1,"marker":"3"}
{"_raw":"2","line-count":3,"line-num":2,"marker":"3"}
{"_raw":"3","line-count":3,"line-num":3,"marker":"3"}

  invocation-time-field

Type: field

Field where invocation time will be stored

Example

Pipe Language Snippet:

exec:
command: |
for n in $(seq 3)
do
echo $n
done
no-strip-linefeeds: true
batch:
invocation-time-field: begin
interval: 1m

Output:

{"_raw":"1","line-count":3,"line-num":1,"begin":"2020-01-17T09:55:09.135Z"}
{"_raw":"2","line-count":3,"line-num":2,"begin":"2020-01-17T09:55:09.135Z"}
{"_raw":"3","line-count":3,"line-num":3,"begin":"2020-01-17T09:55:09.135Z"}

  completion-time-field

Type: field

Field where completion (end of execution) time will be stored

Example

Pipe Language Snippet:

exec:
command: |
for n in $(seq 3)
do
echo $n
done
no-strip-linefeeds: true
batch:
invocation-time-field: begin
completion-time-field: end
interval: 1m

Output:

{"_raw":"1","begin":"2020-01-17T10:02:14.302Z","end":"2020-01-17T10:02:14.301Z","line-count":3,"line-num":1}
{"_raw":"2","begin":"2020-01-17T10:02:14.302Z","end":"2020-01-17T10:02:14.301Z","line-count":3,"line-num":2}
{"_raw":"3","begin":"2020-01-17T10:02:14.302Z","end":"2020-01-17T10:02:14.301Z","line-count":3,"line-num":3}

  begin-marker-field

Type: field

Field used to mark first event in the group

Example

Pipe Language Snippet:

exec:
command: |
for n in $(seq 3)
do
echo $n
done
no-strip-linefeeds: true
batch:
begin-marker-field: begin
interval: 1m

Output:

{"_raw":"1","begin":true,"line-count":3,"line-num":1}
{"_raw":"2","line-count":3,"line-num":2}
{"_raw":"3","line-count":3,"line-num":3}

  end-marker-field

Type: field

Field used to mark last event in the group

Example

Pipe Language Snippet:

exec:
command: |
for n in $(seq 3)
do
echo $n
done
no-strip-linefeeds: true
batch:
begin-marker-field: begin
end-marker-field: end
interval: 1m

Output:

{"_raw":"1","begin":true,"line-count":3,"line-num":1}
{"_raw":"2","line-count":3,"line-num":2}
{"_raw":"3","end":true,"line-count":3,"line-num":3}

  line-count-field

Type: field

Field used to store the line count of the batch

  line-num-field

Type: field

Field used to store the line number of the batch

result

Type: ExecResult

Offers a way to collect the full output of a command: stdout, stdin, and exit status

Field NameTypeDescriptionDefault
status-fieldfieldField where exit status of command will be stored-
stderr-fieldfieldField where stderr of command will be stored-
stdout-fieldfieldField where stdout of command will be stored_raw

  status-field

Type: field

Field where exit status of command will be stored

Example

Pipe Language Snippet:

exec:
command: echo foo
result:
status-field: status

Output:

{"_raw":"foo\n","status":0}

  stderr-field

Type: field

Field where stderr of command will be stored

Example

Input:

{"one":1,"two":2}

Pipe Language Snippet:

exec:
command: "echo \"this will return with an error\" 1>&2 && false"
result:
stderr-field: stderr

Output:

{"one":1,"two":2,"stderr":"this will return with an error"}

  stdout-field

Type: field

Default: _raw

Field where stdout of command will be stored

Example

Pipe Language Snippet:

exec:
command: echo foo
result:
stdout-field: stdout
interval: 1m

Output:

{"stdout":"foo\n"}

raw

Type: bool
Alias: json
Default: false

Do not wrap incoming data in JSON format (i.e. `{"_raw":"some data"})

This is useful when incoming data is already in JSON format.

Example: Enabled

Pipe Language Snippet:

exec:
command: echo one
raw: true

Output:

one

Example: Disabled (default)

Pipe Language Snippet:

exec:
command: echo one

Output:

{"_raw":"one"}

Example: Enabled, with JSON data

Pipe Language Snippet:

exec:
command: echo '{"one":1}'
raw: true

Output:

{"one":1}

Example: Disabled, with JSON data (note the escapes)

Pipe Language Snippet:

exec:
command: echo '{"one":1}'

Output:

{"_raw":"{\"one\":1}"}

count

Type: integer

Number of times to run the command

Example

Pipe Language Snippet:

exec:
command: echo 'one two'
interval: 1s
count: 3

Output:

{"_raw":"one two"}
{"_raw":"one two"}
{"_raw":"one two"}

no-strip-linefeeds

Type: bool

Default: false

Do not strip newline characters (\n) automatically on multi-line commands

Example: Enabled

Pipe Language Snippet:

exec:
command: |
echo one
echo two
no-strip-linefeeds: true

Output:

{"_raw":"one"}
{"_raw":"two"}

Example: Enabled, with a more realistic example (this will fail as one line)

Pipe Language Snippet:

exec:
command: |
for n in $(seq 3)
do
echo $n
done
no-strip-linefeeds: true

Output:

{"_raw":"1"}
{"_raw":"2"}
{"_raw":"3"}

Example: Disabled

Pipe Language Snippet:

exec:
command: |
echo one
echo two

Output:

{"_raw":"one echo two"}

ignore-line-breaks

Type: bool
Alias: ignore-linebreaks
Default: false

Do not treat separate output lines as distinct events

Example: Enabled

Pipe Language Snippet:

exec:
command: |
echo one
echo two
no-strip-linefeeds: true
ignore-line-breaks: true
interval: 1s
count: 1

Output:

{"_raw":"one\ntwo"}

Example: Disabled

Pipe Language Snippet:

exec:
command: |
echo one
echo two
no-strip-linefeeds: true

Output:

{"_raw":"one"}
{"_raw":"two"}

env

Type: path

Accepts a YAML file containing variables that would be added to environment of the command

Example

File: some-file.yml

one: 1
two: 2

Pipe Language Snippet:

exec:
command: echo $one $two
env: some-file.yml

Output:

{"_raw":"1 2"}