view bin/cronic @ 722:b957af519d58

Remove warning on detached head
author nanaya <me@nanaya.net>
date Mon, 19 Aug 2024 17:04:58 +0900
parents 8fa04c2a9896
children
line wrap: on
line source

#!/usr/bin/env bash

# Mod by edogawaconan:
# - `/usr/bin/env bash`
# Source: http://habilis.net/cronic/
#
# Cronic v3 - cron job report wrapper
# Copyright 2007-2016 Chuck Houpt. No rights reserved, whatsoever.
# Public Domain CC0: http://creativecommons.org/publicdomain/zero/1.0/

set -eu

TMP=$(mktemp -d)
OUT=$TMP/cronic.out
ERR=$TMP/cronic.err
TRACE=$TMP/cronic.trace

set +e
"$@" >$OUT 2>$TRACE
RESULT=$?
set -e

PATTERN="^${PS4:0:1}\\+${PS4:1}"
if grep -aq "$PATTERN" $TRACE
then
    ! grep -av "$PATTERN" $TRACE > $ERR
else
    ERR=$TRACE
fi

if [ $RESULT -ne 0 -o -s "$ERR" ]
    then
    echo "Cronic detected failure or error output for the command:"
    echo "$@"
    echo
    echo "RESULT CODE: $RESULT"
    echo
    echo "ERROR OUTPUT:"
    cat "$ERR"
    echo
    echo "STANDARD OUTPUT:"
    cat "$OUT"
    if [ $TRACE != $ERR ]
    then
        echo
        echo "TRACE-ERROR OUTPUT:"
        cat "$TRACE"
    fi
fi

rm -rf "$TMP"