Created
June 1, 2020 03:02
-
-
Save fakuivan/0b4bb17904a2f3bef30e15d0086a33bc to your computer and use it in GitHub Desktop.
cron is π©
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin" | |
# https://stackoverflow.com/a/26827443 | |
# shellcheck disable=SC2030,SC2034,SC2031 | |
split_output() { | |
local -n array="$1" || return $?; | |
# shellcheck disable=SC1090 | |
. <({ | |
err="$({ out="$("${@:2}")"; ret=$?; } 2>&1; | |
declare -p out ret >&2)"; | |
declare -p err; | |
} 2>&1); | |
array=("$out" "$err"); | |
return $ret; | |
} | |
LOG_FILE="$HOME/cron_log.txt" | |
COMMAND="$1" | |
split_output result /bin/bash -l -c "$COMMAND" | |
result+=( "$?" ) | |
echo "[$(date -Iseconds)] ${COMMAND@Q}: $(declare -p result)" | tee -a "$LOG_FILE" | |
exit "${result[-1]}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment