diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
commit | e6918187568dbd01842d8d1d2c808ce16a894239 (patch) | |
tree | 64f88b554b444a49f656b6c656111a145cbbaa28 /qa/nightlies/cron_wrapper | |
parent | Initial commit. (diff) | |
download | ceph-e6918187568dbd01842d8d1d2c808ce16a894239.tar.xz ceph-e6918187568dbd01842d8d1d2c808ce16a894239.zip |
Adding upstream version 18.2.2.upstream/18.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'qa/nightlies/cron_wrapper')
-rwxr-xr-x | qa/nightlies/cron_wrapper | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/qa/nightlies/cron_wrapper b/qa/nightlies/cron_wrapper new file mode 100755 index 000000000..29b4483e9 --- /dev/null +++ b/qa/nightlies/cron_wrapper @@ -0,0 +1,53 @@ +#!/usr/bin/env 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" +# set $LOG_LOCKED_ERR in case locking failed +LOG_LOCK_ERR="/var/log/crontab-nightlies-log/crontab_lock_problem.$$" + +# temp files to store stdout 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 + +DATE=$(date) +echo -n "$DATE: " >> $STDOUT +echo "Running command: $@" >> $STDOUT +"$@" > $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 + + # lock $LOG with file descriptor 200 + exec 200>>$LOG + # if $LOG is locked by other process - wait for 20 sec + flock -w 20 200 || LOG=$LOG_LOCK_ERR + echo "stdout:" >> $LOG + cat $STDOUT >> $LOG + echo "stderr:" >> $LOG + cat $STDERR >> $LOG + # unlock + flock -u 200 +fi |