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

Clash 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.
linux bash cron parameter
add a comment |Â
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.
linux bash cron parameter
add a comment |Â
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.
linux bash cron parameter
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
linux bash cron parameter
edited Aug 11 at 13:34
Jeff Schaller
32.4k849110
32.4k849110
asked Aug 10 at 17:10
calicowboy23
161
161
add a comment |Â
add a comment |Â
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.
add a comment |Â
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)
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
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.
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.
edited Aug 10 at 17:45
answered Aug 10 at 17:37
Tagwint
1,3181613
1,3181613
add a comment |Â
add a comment |Â
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)
add a comment |Â
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)
add a comment |Â
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)
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)
edited Aug 10 at 17:52
answered Aug 10 at 17:42
user1133275
2,277412
2,277412
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password