How to pass in log file creation to pass in to script to attach the file

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I have several cron jobs I run to back up dbs:



0 8 * * * BACKUP=DEV DB=01 /usr/local/bin/backup.sh > /var/log/backup-db01-`date "+%m%d%y"`.log 2>&1||/usr/local/bin/create-ticket.sh

0 16 * * * BACKUP=DEV DB=02 /usr/local/bin/backup.sh > /var/log/backup-db02-`date "+%m%d%y"`.log 2>&1||/usr/local/bin/create-ticket.sh


In the script I am trying to create JIRA ticket on failure and attach the logs for the backup:



create-ticket.sh script:



#create Ticket for failed backup#
JIRA=`/opt/atlassian-cli/jira.sh --server https://blahblah --user admin --password blahblah --action createIssue --project "DEV" --type "Incident" --summary "Failed backup on $BACKUP $DB" --components "blah" --priority "Major"| awk 'print $2'`

###Atttach logs:###
/opt/atlassian-cli/jira.sh --server https://blahblah --user admin --password blahblah --action addAttachment --issue "$JIRA" --file "?????"


I need to know how to pass in the different file names for each time the cron runs to the --file "???" section... the file name changes daily and i need the script to pick up the newly created file for each DB on each day it fails.










share|improve this question



























    up vote
    0
    down vote

    favorite












    I have several cron jobs I run to back up dbs:



    0 8 * * * BACKUP=DEV DB=01 /usr/local/bin/backup.sh > /var/log/backup-db01-`date "+%m%d%y"`.log 2>&1||/usr/local/bin/create-ticket.sh

    0 16 * * * BACKUP=DEV DB=02 /usr/local/bin/backup.sh > /var/log/backup-db02-`date "+%m%d%y"`.log 2>&1||/usr/local/bin/create-ticket.sh


    In the script I am trying to create JIRA ticket on failure and attach the logs for the backup:



    create-ticket.sh script:



    #create Ticket for failed backup#
    JIRA=`/opt/atlassian-cli/jira.sh --server https://blahblah --user admin --password blahblah --action createIssue --project "DEV" --type "Incident" --summary "Failed backup on $BACKUP $DB" --components "blah" --priority "Major"| awk 'print $2'`

    ###Atttach logs:###
    /opt/atlassian-cli/jira.sh --server https://blahblah --user admin --password blahblah --action addAttachment --issue "$JIRA" --file "?????"


    I need to know how to pass in the different file names for each time the cron runs to the --file "???" section... the file name changes daily and i need the script to pick up the newly created file for each DB on each day it fails.










    share|improve this question

























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have several cron jobs I run to back up dbs:



      0 8 * * * BACKUP=DEV DB=01 /usr/local/bin/backup.sh > /var/log/backup-db01-`date "+%m%d%y"`.log 2>&1||/usr/local/bin/create-ticket.sh

      0 16 * * * BACKUP=DEV DB=02 /usr/local/bin/backup.sh > /var/log/backup-db02-`date "+%m%d%y"`.log 2>&1||/usr/local/bin/create-ticket.sh


      In the script I am trying to create JIRA ticket on failure and attach the logs for the backup:



      create-ticket.sh script:



      #create Ticket for failed backup#
      JIRA=`/opt/atlassian-cli/jira.sh --server https://blahblah --user admin --password blahblah --action createIssue --project "DEV" --type "Incident" --summary "Failed backup on $BACKUP $DB" --components "blah" --priority "Major"| awk 'print $2'`

      ###Atttach logs:###
      /opt/atlassian-cli/jira.sh --server https://blahblah --user admin --password blahblah --action addAttachment --issue "$JIRA" --file "?????"


      I need to know how to pass in the different file names for each time the cron runs to the --file "???" section... the file name changes daily and i need the script to pick up the newly created file for each DB on each day it fails.










      share|improve this question















      I have several cron jobs I run to back up dbs:



      0 8 * * * BACKUP=DEV DB=01 /usr/local/bin/backup.sh > /var/log/backup-db01-`date "+%m%d%y"`.log 2>&1||/usr/local/bin/create-ticket.sh

      0 16 * * * BACKUP=DEV DB=02 /usr/local/bin/backup.sh > /var/log/backup-db02-`date "+%m%d%y"`.log 2>&1||/usr/local/bin/create-ticket.sh


      In the script I am trying to create JIRA ticket on failure and attach the logs for the backup:



      create-ticket.sh script:



      #create Ticket for failed backup#
      JIRA=`/opt/atlassian-cli/jira.sh --server https://blahblah --user admin --password blahblah --action createIssue --project "DEV" --type "Incident" --summary "Failed backup on $BACKUP $DB" --components "blah" --priority "Major"| awk 'print $2'`

      ###Atttach logs:###
      /opt/atlassian-cli/jira.sh --server https://blahblah --user admin --password blahblah --action addAttachment --issue "$JIRA" --file "?????"


      I need to know how to pass in the different file names for each time the cron runs to the --file "???" section... the file name changes daily and i need the script to pick up the newly created file for each DB on each day it fails.







      linux bash cron parameter






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 11 at 13:34









      Jeff Schaller

      32.4k849110




      32.4k849110










      asked Aug 10 at 17:10









      calicowboy23

      161




      161




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote













          I think you can introduce log file name parameter to be used for both redirection and when calling create-ticket.sh



          0 8 * * * BACKUP=DEV DB=01 LOG=/var/log/backup-db01-$(date "+%m%d%y").log /usr/local/bin/backup.sh > $LOG 2>&1 || /usr/local/bin/create-ticket.sh $LOG


          so create-ticked.sh should be then expecting that parameter and you can use it inside like



           ... --file "$1" ...


          You may not want to use escaping % sign - $(date "+%m%d%y") - part will result in string like 021318 once so you guaranteed to stick with the same name.






          share|improve this answer





























            up vote
            0
            down vote













            Make a wrapper script to clean up your crontab;



            0 8 * * * /usr/local/bin/backupOrTicket.sh 01


            and put this in it;



            DB=$1
            BACKUP=DEV
            FILE="/var/log/backup-$DB-$(date +%m%d%y).log"
            /usr/local/bin/backup.sh > "$FILE" 2>&1
            || /usr/local/bin/create-ticket.sh "$FILE"


            Using --file "$1" in create-ticket.sh . You might want to remove the BACKUP variable if it's not actually used. Also you should use date --iso-8601=s so that your log files sort properly. (Using any date format other than numerical largest to smallest is an anti pattern)






            share|improve this answer






















              Your Answer







              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "106"
              ;
              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',
              convertImagesToLinks: false,
              noModals: false,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













               

              draft saved


              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f461858%2fhow-to-pass-in-log-file-creation-to-pass-in-to-script-to-attach-the-file%23new-answer', 'question_page');

              );

              Post as a guest






























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              0
              down vote













              I think you can introduce log file name parameter to be used for both redirection and when calling create-ticket.sh



              0 8 * * * BACKUP=DEV DB=01 LOG=/var/log/backup-db01-$(date "+%m%d%y").log /usr/local/bin/backup.sh > $LOG 2>&1 || /usr/local/bin/create-ticket.sh $LOG


              so create-ticked.sh should be then expecting that parameter and you can use it inside like



               ... --file "$1" ...


              You may not want to use escaping % sign - $(date "+%m%d%y") - part will result in string like 021318 once so you guaranteed to stick with the same name.






              share|improve this answer


























                up vote
                0
                down vote













                I think you can introduce log file name parameter to be used for both redirection and when calling create-ticket.sh



                0 8 * * * BACKUP=DEV DB=01 LOG=/var/log/backup-db01-$(date "+%m%d%y").log /usr/local/bin/backup.sh > $LOG 2>&1 || /usr/local/bin/create-ticket.sh $LOG


                so create-ticked.sh should be then expecting that parameter and you can use it inside like



                 ... --file "$1" ...


                You may not want to use escaping % sign - $(date "+%m%d%y") - part will result in string like 021318 once so you guaranteed to stick with the same name.






                share|improve this answer
























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  I think you can introduce log file name parameter to be used for both redirection and when calling create-ticket.sh



                  0 8 * * * BACKUP=DEV DB=01 LOG=/var/log/backup-db01-$(date "+%m%d%y").log /usr/local/bin/backup.sh > $LOG 2>&1 || /usr/local/bin/create-ticket.sh $LOG


                  so create-ticked.sh should be then expecting that parameter and you can use it inside like



                   ... --file "$1" ...


                  You may not want to use escaping % sign - $(date "+%m%d%y") - part will result in string like 021318 once so you guaranteed to stick with the same name.






                  share|improve this answer














                  I think you can introduce log file name parameter to be used for both redirection and when calling create-ticket.sh



                  0 8 * * * BACKUP=DEV DB=01 LOG=/var/log/backup-db01-$(date "+%m%d%y").log /usr/local/bin/backup.sh > $LOG 2>&1 || /usr/local/bin/create-ticket.sh $LOG


                  so create-ticked.sh should be then expecting that parameter and you can use it inside like



                   ... --file "$1" ...


                  You may not want to use escaping % sign - $(date "+%m%d%y") - part will result in string like 021318 once so you guaranteed to stick with the same name.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Aug 10 at 17:45

























                  answered Aug 10 at 17:37









                  Tagwint

                  1,3181613




                  1,3181613






















                      up vote
                      0
                      down vote













                      Make a wrapper script to clean up your crontab;



                      0 8 * * * /usr/local/bin/backupOrTicket.sh 01


                      and put this in it;



                      DB=$1
                      BACKUP=DEV
                      FILE="/var/log/backup-$DB-$(date +%m%d%y).log"
                      /usr/local/bin/backup.sh > "$FILE" 2>&1
                      || /usr/local/bin/create-ticket.sh "$FILE"


                      Using --file "$1" in create-ticket.sh . You might want to remove the BACKUP variable if it's not actually used. Also you should use date --iso-8601=s so that your log files sort properly. (Using any date format other than numerical largest to smallest is an anti pattern)






                      share|improve this answer


























                        up vote
                        0
                        down vote













                        Make a wrapper script to clean up your crontab;



                        0 8 * * * /usr/local/bin/backupOrTicket.sh 01


                        and put this in it;



                        DB=$1
                        BACKUP=DEV
                        FILE="/var/log/backup-$DB-$(date +%m%d%y).log"
                        /usr/local/bin/backup.sh > "$FILE" 2>&1
                        || /usr/local/bin/create-ticket.sh "$FILE"


                        Using --file "$1" in create-ticket.sh . You might want to remove the BACKUP variable if it's not actually used. Also you should use date --iso-8601=s so that your log files sort properly. (Using any date format other than numerical largest to smallest is an anti pattern)






                        share|improve this answer
























                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          Make a wrapper script to clean up your crontab;



                          0 8 * * * /usr/local/bin/backupOrTicket.sh 01


                          and put this in it;



                          DB=$1
                          BACKUP=DEV
                          FILE="/var/log/backup-$DB-$(date +%m%d%y).log"
                          /usr/local/bin/backup.sh > "$FILE" 2>&1
                          || /usr/local/bin/create-ticket.sh "$FILE"


                          Using --file "$1" in create-ticket.sh . You might want to remove the BACKUP variable if it's not actually used. Also you should use date --iso-8601=s so that your log files sort properly. (Using any date format other than numerical largest to smallest is an anti pattern)






                          share|improve this answer














                          Make a wrapper script to clean up your crontab;



                          0 8 * * * /usr/local/bin/backupOrTicket.sh 01


                          and put this in it;



                          DB=$1
                          BACKUP=DEV
                          FILE="/var/log/backup-$DB-$(date +%m%d%y).log"
                          /usr/local/bin/backup.sh > "$FILE" 2>&1
                          || /usr/local/bin/create-ticket.sh "$FILE"


                          Using --file "$1" in create-ticket.sh . You might want to remove the BACKUP variable if it's not actually used. Also you should use date --iso-8601=s so that your log files sort properly. (Using any date format other than numerical largest to smallest is an anti pattern)







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Aug 10 at 17:52

























                          answered Aug 10 at 17:42









                          user1133275

                          2,277412




                          2,277412



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f461858%2fhow-to-pass-in-log-file-creation-to-pass-in-to-script-to-attach-the-file%23new-answer', 'question_page');

                              );

                              Post as a guest













































































                              Popular posts from this blog

                              Peggy Mitchell

                              Palaiologos

                              The Forum (Inglewood, California)