diff options
| author | EuAndreh <eu@euandre.org> | 2023-03-13 10:04:33 -0300 |
|---|---|---|
| committer | EuAndreh <eu@euandre.org> | 2023-03-13 10:06:10 -0300 |
| commit | f00b68077e634f75b4b27670d74d37fbc4287544 (patch) | |
| tree | 89eb7cade2f47e6d0f8bef557c667ae0926314ac /bin | |
| parent | etc/nix/configuration.nix: Configure postfix to redirect local emails to euan... (diff) | |
| download | dotfiles-f00b68077e634f75b4b27670d74d37fbc4287544.tar.gz dotfiles-f00b68077e634f75b4b27670d74d37fbc4287544.tar.xz | |
Embed with-email(1) into cronjob(1) and improve its reporting
Diffstat (limited to 'bin')
| -rwxr-xr-x | bin/with-email | 92 |
1 files changed, 0 insertions, 92 deletions
diff --git a/bin/with-email b/bin/with-email deleted file mode 100755 index 02789e9..0000000 --- a/bin/with-email +++ /dev/null @@ -1,92 +0,0 @@ -#!/bin/sh -set -eu - -usage() { - cat <<-'EOF' - Usage: - with-email [-s SUBJECT] COMMAND... - with-email -h - EOF -} - -help() { - cat <<-'EOF' - - Options: - -s SUBJECT set the subject of the email - -h, --help show this message - - COMMAND the command to be wrapped - - - Executes COMMAND and send all of its output via email - to eu@euandre.org. - - - Examples: - - Run a script and use the default subject: - - $ with-email -- ./script - - Run a command and use a custom subject: - - $ with-email -s 'CRONJOB' echo 123 - EOF -} - -for flag in "$@"; do - case "$flag" in - --) - break - ;; - --help) - usage - help - exit - ;; - *) - ;; - esac -done - -SUBJECT='NO SUBJECT' -while getopts 's:h' flag; do - case "$flag" in - s) - SUBJECT="$OPTARG" - ;; - h) - usage - help - exit - ;; - *) - usage >&2 - exit 2 - ;; - esac -done -shift $((OPTIND - 1)) - -eval "$(assert-arg -- "${1:-}" 'COMMAND...')" - -now() { - date '+%Y-%m-%dT%H:%M:%S%Z' -} - -OUT="$(mkstemp)" -trap 'rm -f "$OUT"' EXIT -{ - printf 'Running command: %s\n' "$*" - printf 'Starting at: %s\n' "$(now)" - printf '\n' - - STATUS=0 - "$@" || STATUS=$? - - printf '\n' - printf '\nFinished at: %s\n' "$(now)" -} 1>"$OUT" 2>&1 - -email -s "(exit status: $STATUS) - $SUBJECT" eu@euandre.org < "$OUT" |
