]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
A script to be used in crontab sepia nd ovh lab, so emails sent only on errors
authorYuri Weinstein <yweinste@redhat.com>
Mon, 9 May 2016 20:01:04 +0000 (13:01 -0700)
committerYuri Weinstein <yweinste@redhat.com>
Fri, 13 May 2016 01:30:34 +0000 (18:30 -0700)
Fixes: http://tracker.ceph.com/issues/15563
Signed-off-by: Yuri Weinstein <yweinste@redhat.com>
nightlies/cron_wrapper [new file with mode: 0644]

diff --git a/nightlies/cron_wrapper b/nightlies/cron_wrapper
new file mode 100644 (file)
index 0000000..78b5f0a
--- /dev/null
@@ -0,0 +1,39 @@
+#!/bin/bash
+# /nightlies/cron_wrapper.sh
+
+# check for no argument case and stop
+if [ -z $1 ]; then
+  echo "need argument"
+  exit 1
+fi
+
+# set permanent $LOG file var
+LOG="/var/log/crontab-nightlies-log/crontab.log"
+
+# temp files to store sdtout and stderr
+# named with the PID of this script in their name so they'll be unique
+STDERR="/var/tmp/stderr.$$"
+STDOUT="/var/tmp/stdout.$$"
+
+# $STDOUT and $STDERR are removed when the script exits for any reason
+trap  "rm -f $STDOUT $STDERR" 0
+
+# run a command from this script's argument
+# redirect stdout to $STDOUT file and redirect stderr to $STDERR file
+"$@" > $STDOUT 2> $STDERR
+
+# get return code from the command run
+code=$?
+
+if [ $code != 0 ] ; then
+        # echoing to stdout/stderr makes cron send email
+        echo "stdout:"
+        cat $STDOUT
+        echo "stderr:"
+        cat $STDERR
+else
+        # normal exit: just log stdout
+        DATE=$(date)
+        echo -n "$DATE: " >> $LOG
+        cat $STDOUT  >> $LOG
+fi