aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2023-03-13 10:04:33 -0300
committerEuAndreh <eu@euandre.org>2023-03-13 10:06:10 -0300
commitf00b68077e634f75b4b27670d74d37fbc4287544 (patch)
tree89eb7cade2f47e6d0f8bef557c667ae0926314ac /bin
parentetc/nix/configuration.nix: Configure postfix to redirect local emails to euan... (diff)
downloaddotfiles-f00b68077e634f75b4b27670d74d37fbc4287544.tar.gz
dotfiles-f00b68077e634f75b4b27670d74d37fbc4287544.tar.xz
Embed with-email(1) into cronjob(1) and improve its reporting
Diffstat (limited to 'bin')
-rwxr-xr-xbin/with-email92
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"