summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xscripts/run-with-log.sh21
1 files changed, 15 insertions, 6 deletions
diff --git a/scripts/run-with-log.sh b/scripts/run-with-log.sh
index 2dd05c0..43996f1 100755
--- a/scripts/run-with-log.sh
+++ b/scripts/run-with-log.sh
@@ -21,6 +21,8 @@ License: GPLv3+
set -u
+# Save command line arguments for FATAL ERROR emails
+cmdline="$0 $*"
die()
{
@@ -34,11 +36,19 @@ die_with_log()
{
## Runtime error, try to send some notification...
BASE=$(basename "$0")
- echo "$BASE: error: $*" >&2
+
+ MSG1="$BASE: error: $*"
+ MSG2="Command line was: $cmdline"
+ ID=$(id 2>/dev/null)
+ MSG3="ID: $ID"
+
if test -n "$email" ; then
- echo "$BASE: error: $*" \
+ { echo "$MSG1" ; echo "$MSG2" ; echo "$MSG3" ; } \
| mail -s "run-with-log: FATAL RUNTIME ERROR" "$email"
fi
+
+ { echo "$MSG1" ; echo "$MSG2" ; echo "$MSG3" ; } >&2
+
exit 1
}
@@ -94,7 +104,7 @@ Usage: $BASE [OPTIONS] -- COMMAND [ARGS]
OPTIONS:
-h - This help screen.
- -e EMAIL - Email log to this address (default: $USER).
+ -e EMAIL - Email log to this address (default: \$USER, fallback to root).
-A - Always email logs (default: only on COMMAND failure)
-L FILE - Write log to FILE (disables auto filename generation).
-p PREFIX - Write log to PREFIX with '-{DATE}.log' suffix appended.
@@ -168,9 +178,8 @@ test -z "$name" \
# This of course requires that the MTA is properly
# configured on the host.
if test -z "$email" ; then
- # FIXME: 'set -u' is defined: will this even work?
- test -z "$USER" && die "no email specified (-e), and \$USER is empty."
- email="$USER"
+ # Use current user, fallback to root
+ email="${USER:-root}"
fi
##