summaryrefslogtreecommitdiff
path: root/scripts/mail-logger.sh
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/mail-logger.sh')
-rwxr-xr-xscripts/mail-logger.sh29
1 files changed, 29 insertions, 0 deletions
diff --git a/scripts/mail-logger.sh b/scripts/mail-logger.sh
new file mode 100755
index 0000000..5734a28
--- /dev/null
+++ b/scripts/mail-logger.sh
@@ -0,0 +1,29 @@
+# Script mailer
+
+if [ "$1" = "" -o "$2" = "" ] ; then
+ echo "Usage"
+ echo "$0 <mailto> <script> [<script_args> ...]"
+ exit 1
+fi
+
+MAILTO="$1";
+BASE="/tmp/$$"
+LOGO="${BASE}o";
+LOGE="${BASE}e";
+SCRIPT="${BASE}s";
+shift;
+
+# Execute the script
+echo "$@" > "${SCRIPT}";
+chmod +x "${SCRIPT}"
+"${SCRIPT}" > "${LOGO}" 2> "${LOGE}";
+
+if [ -s "${LOGE}" ] ; then
+ mailx -s "Errors from ${1}" "${MAILTO}" < "${LOGE}";
+fi
+if [ -s "${LOGO}" ] ; then
+ mailx -s "Output from ${1}" "${MAILTO}" < "${LOGO}";
+fi
+rm "${LOGO}" "${LOGE}" "${SCRIPT}"
+
+