Last active
October 17, 2022 17:23
-
-
Save moonexpr/74d9e2488f33c636a438b2f781cf1748 to your computer and use it in GitHub Desktop.
bash_diligence <program>: Allows you to run a program in the background while telling you if it fails.
This file contains 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 | |
# notify: Instantiates a new push notification. | |
# $1 string title | |
# $2 string body | |
notify() | |
{ | |
NOTIFY_OPTS="-a $0 -i utilities-terminal -t 8000" | |
notify-send ${NOTIFY_OPTS} "$1" "$2" | |
} | |
if [[ $# < 1 ]]; then | |
echo "Usage: bash_diligence <program> {args}" | |
exit 1 | |
fi | |
ERR=$({ $1 ${@:2} 1>- 2>&3; } 3>&1) | |
# res: exit code 0, happy ending> | |
EXIT_CODE=$? | |
[[ $EXIT_CODE = 0 ]] && exit 0 | |
# res: exit code 0<, err ending. | |
SCRIPT_NAME=$(basename $1) | |
SCRIPT_NAME=${SCRIPT_NAME^} | |
if [[ "$ERR" ]]; then | |
notify "$SCRIPT_NAME: Runtime Error" "$ERR" | |
else | |
notify "$SCRIPT_NAME: Runtime Anomaly" "Script exited with #$EXIT_CODE. There is no error message available." | |
fi | |
Author
moonexpr
commented
Sep 17, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment