Execute after completion
Sometimes you want to execute another command after the main command executes, this is often the case when you want to check the status of the main command, or if you want to send a notification.
config.yamlactions:
- title: Check date and send notification via apprise
icon: date
shell: date
shellAfterCompleted: "apprise -c /config/apprise.yml -t 'Notification: Backup script completed' -b \"$(printf 'Backup completed with exit code %s. Log: %s' {{ exitCode }} {{ output }})\""
When running shellAfterCompleted, you cannot use user-defined argument values - they are not passed to the command. However the following special arguments are defined;
-
{{ exitCode }}/{{ .Arguments.exitCode }}- The exit code of the previous command. OliveTin rewrites these placeholders to the quoted"$EXITCODE"environment reference when runningshellAfterCompleted, so shell metacharacters in the value cannot break quoting. Placeholders inside single-quoted shell arguments are rewritten so the environment reference can still expand. -
{{ output }}/{{ .Arguments.output }}- The standard output of the previous command. OliveTin rewrites these placeholders to the quoted"$OUTPUT"environment reference, so shell metacharacters in command output cannot be executed. You can also reference$OUTPUTdirectly in yourshellAfterCompletedcommand. Placeholders inside single-quoted shell arguments are rewritten so the environment reference can still expand. -
{{ .Arguments.ot_executionTrackingId }}- The unique execution tracking id for this execution (version 3k; in 2k use{{ ot_executionTrackingId }}) -
{{ .Arguments.ot_username }}- The username of the user who started the execution (version 3k; in 2k use{{ ot_username }}). May beguestorcronfor unauthenticated or automated runs.
Webhooks cannot use shellAfterCompleted (or shell:). Use exec: for webhook-triggered actions without an after-completion shell. See Shell vs Exec.
You can only use a single shellAfterCompleted, so use it for notifications, or similar. It would be an antipattern to use this do run 2 commands making up a mini script.
The official OliveTin container images from version 2024.03.24 onwards include the fantastic apprise tool, which makes chat notifications on many protocols very easy.
/config/apprise.yamlurls:
- tgram://bottoken/ChatID
See Also
-
Triggers - Executing full actions after this one (with separate arguments, etc).