using cronic to reduce email notifications in a wrapper script for successful backups










0















I've been using cronic to silence emails from cron jobs when the job is successful. I'm trying to customize it so when a response code is 0 and the error output matches a string of "mount: /VessRAID/RH: /dev/sde1 already mounted on /VessRAID/RH.", to not send an email. Below is the script, then the contents of the email then my attempt at trying to suppress the email which is not working. Any idea what I may be doing wrong?



#!/bin/bash
# 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"


Here is what the email notification looks like:



 Cronic detected failure or error output for the command:
/usr/local/sbin/reg-backup-cronic.sh daily

RESULT CODE: 0

ERROR OUTPUT:
mount: /VessRAID/RH: /dev/sde1 already mounted on /VessRAID/RH.

STANDARD OUTPUT:
/dev/sde1 on /VessRAID/RH type ext4 (rw,relatime)


Here is my attempt at a wrapper script:



#!/bin/bash
/usr/local/sbin/reg-backup.sh $1
CODE=$?
err=$TRACE
if [[ $CODE -eq 0 && $err = "mount: /VessRAID/RH: /dev/sde1 already mounted on /VessRAID/RH." ]]
then
exit $CODE
fi


Alas the emails continue.










share|improve this question


























    0















    I've been using cronic to silence emails from cron jobs when the job is successful. I'm trying to customize it so when a response code is 0 and the error output matches a string of "mount: /VessRAID/RH: /dev/sde1 already mounted on /VessRAID/RH.", to not send an email. Below is the script, then the contents of the email then my attempt at trying to suppress the email which is not working. Any idea what I may be doing wrong?



    #!/bin/bash
    # 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"


    Here is what the email notification looks like:



     Cronic detected failure or error output for the command:
    /usr/local/sbin/reg-backup-cronic.sh daily

    RESULT CODE: 0

    ERROR OUTPUT:
    mount: /VessRAID/RH: /dev/sde1 already mounted on /VessRAID/RH.

    STANDARD OUTPUT:
    /dev/sde1 on /VessRAID/RH type ext4 (rw,relatime)


    Here is my attempt at a wrapper script:



    #!/bin/bash
    /usr/local/sbin/reg-backup.sh $1
    CODE=$?
    err=$TRACE
    if [[ $CODE -eq 0 && $err = "mount: /VessRAID/RH: /dev/sde1 already mounted on /VessRAID/RH." ]]
    then
    exit $CODE
    fi


    Alas the emails continue.










    share|improve this question
























      0












      0








      0








      I've been using cronic to silence emails from cron jobs when the job is successful. I'm trying to customize it so when a response code is 0 and the error output matches a string of "mount: /VessRAID/RH: /dev/sde1 already mounted on /VessRAID/RH.", to not send an email. Below is the script, then the contents of the email then my attempt at trying to suppress the email which is not working. Any idea what I may be doing wrong?



      #!/bin/bash
      # 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"


      Here is what the email notification looks like:



       Cronic detected failure or error output for the command:
      /usr/local/sbin/reg-backup-cronic.sh daily

      RESULT CODE: 0

      ERROR OUTPUT:
      mount: /VessRAID/RH: /dev/sde1 already mounted on /VessRAID/RH.

      STANDARD OUTPUT:
      /dev/sde1 on /VessRAID/RH type ext4 (rw,relatime)


      Here is my attempt at a wrapper script:



      #!/bin/bash
      /usr/local/sbin/reg-backup.sh $1
      CODE=$?
      err=$TRACE
      if [[ $CODE -eq 0 && $err = "mount: /VessRAID/RH: /dev/sde1 already mounted on /VessRAID/RH." ]]
      then
      exit $CODE
      fi


      Alas the emails continue.










      share|improve this question














      I've been using cronic to silence emails from cron jobs when the job is successful. I'm trying to customize it so when a response code is 0 and the error output matches a string of "mount: /VessRAID/RH: /dev/sde1 already mounted on /VessRAID/RH.", to not send an email. Below is the script, then the contents of the email then my attempt at trying to suppress the email which is not working. Any idea what I may be doing wrong?



      #!/bin/bash
      # 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"


      Here is what the email notification looks like:



       Cronic detected failure or error output for the command:
      /usr/local/sbin/reg-backup-cronic.sh daily

      RESULT CODE: 0

      ERROR OUTPUT:
      mount: /VessRAID/RH: /dev/sde1 already mounted on /VessRAID/RH.

      STANDARD OUTPUT:
      /dev/sde1 on /VessRAID/RH type ext4 (rw,relatime)


      Here is my attempt at a wrapper script:



      #!/bin/bash
      /usr/local/sbin/reg-backup.sh $1
      CODE=$?
      err=$TRACE
      if [[ $CODE -eq 0 && $err = "mount: /VessRAID/RH: /dev/sde1 already mounted on /VessRAID/RH." ]]
      then
      exit $CODE
      fi


      Alas the emails continue.







      shell cron






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 12 '18 at 19:11









      RobbieTheKRobbieTheK

      247




      247






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Hat tip to the creator of cronic, Chuck Houpt, for cluing me in to an answer, which was to look at the original script and why the error is happening. Case-sensitivity got the best of me:



          if mount | grep Vessraid; then
          echo starting $1 backup >> /var/log/vessraid.log


          Notice the case in VessRAID should have been:



          if mount | grep VessRAID; then
          echo starting $1 backup >> /var/log/vessraid.log


          Now emails only happen when there really is an error.






          share|improve this answer






















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53268621%2fusing-cronic-to-reduce-email-notifications-in-a-wrapper-script-for-successful-ba%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Hat tip to the creator of cronic, Chuck Houpt, for cluing me in to an answer, which was to look at the original script and why the error is happening. Case-sensitivity got the best of me:



            if mount | grep Vessraid; then
            echo starting $1 backup >> /var/log/vessraid.log


            Notice the case in VessRAID should have been:



            if mount | grep VessRAID; then
            echo starting $1 backup >> /var/log/vessraid.log


            Now emails only happen when there really is an error.






            share|improve this answer



























              0














              Hat tip to the creator of cronic, Chuck Houpt, for cluing me in to an answer, which was to look at the original script and why the error is happening. Case-sensitivity got the best of me:



              if mount | grep Vessraid; then
              echo starting $1 backup >> /var/log/vessraid.log


              Notice the case in VessRAID should have been:



              if mount | grep VessRAID; then
              echo starting $1 backup >> /var/log/vessraid.log


              Now emails only happen when there really is an error.






              share|improve this answer

























                0












                0








                0







                Hat tip to the creator of cronic, Chuck Houpt, for cluing me in to an answer, which was to look at the original script and why the error is happening. Case-sensitivity got the best of me:



                if mount | grep Vessraid; then
                echo starting $1 backup >> /var/log/vessraid.log


                Notice the case in VessRAID should have been:



                if mount | grep VessRAID; then
                echo starting $1 backup >> /var/log/vessraid.log


                Now emails only happen when there really is an error.






                share|improve this answer













                Hat tip to the creator of cronic, Chuck Houpt, for cluing me in to an answer, which was to look at the original script and why the error is happening. Case-sensitivity got the best of me:



                if mount | grep Vessraid; then
                echo starting $1 backup >> /var/log/vessraid.log


                Notice the case in VessRAID should have been:



                if mount | grep VessRAID; then
                echo starting $1 backup >> /var/log/vessraid.log


                Now emails only happen when there really is an error.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered yesterday









                RobbieTheKRobbieTheK

                247




                247



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53268621%2fusing-cronic-to-reduce-email-notifications-in-a-wrapper-script-for-successful-ba%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Use pre created SQLite database for Android project in kotlin

                    Darth Vader #20

                    Ondo