LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to pass in echo of log file creation to pass in to script to attach the file (https://www.linuxquestions.org/questions/programming-9/how-to-pass-in-echo-of-log-file-creation-to-pass-in-to-script-to-attach-the-file-4175636106/)

krazykracker 08-10-2018 11:44 AM

How to pass in echo of log file creation to pass in to script to attach the file
 
I have a Cron that is running that at script that backs up data is passing in variables to the backup and create script i need to know how to take the log file im passing and add to the

CRON:
BACKUP=DEV /usr/local/bin/backup.sh > /var/log/backup-`date "+\%m\%d\%y"`.log 2>&1||/usr/local/bin/create-ticket.sh

in script create-ticket.sh i have the following:


#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" --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 get the file name of this cron output "/var/log/backup-`date "+\%m\%d\%y"`.log" in to the section (--file "????")

i know i can do a Variable=/var/log/backup-`date "+\%m\%d\%y"`.log & pass in $Variable but i don't want to do that.


any help would be appreciated.

scasey 08-10-2018 12:21 PM

one way:
pass the name of the log file being created into /usr/local/bin/create-ticket.sh
Code:

/usr/local/bin/create-ticket.sh /var/log/backup-`date "+\%m\%d\%y"`.log
then use the $1 parameter in the create-ticket.sh script for the --file parameter:
Code:

... --file "$1"
I realize that's similar to the thing you don't want to do, and if the backup runs just before midnight and the create-ticket just after midnight the date command would return different dates.

Why don't you want to use a variable to hold the log file name? (It would still have to be passed in as above unless exported)


All times are GMT -5. The time now is 10:40 AM.