From fd70e27b5d3676f1d263d6b4f07a781975cbaa8b Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Fri, 14 Jun 2024 11:50:48 +0200 Subject: [PATCH] change output redirection strategy --- run_xexe.sh | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/run_xexe.sh b/run_xexe.sh index 4ffdd50..04cd746 100644 --- a/run_xexe.sh +++ b/run_xexe.sh @@ -1,5 +1,9 @@ #!/bin/bash +exec >> /home/azureuser/xexe_run.log 2>&1 + +echo "Starting script at $(date)" + # Define the Slack webhook URL script_dir=$(dirname "$0") webhooks_file="slack_webhook_urls.txt" @@ -21,24 +25,24 @@ has_any_step_failed=0 cd /home/azureuser/data-xexe # Update from git -echo "Updating xexe project from git." | while IFS= read -r line; do printf '%s %s\n' "$(date)" "$line"; done >> /home/azureuser/xexe_run.log 2>&1 -git checkout master | while IFS= read -r line; do printf '%s %s\n' "$(date)" "$line"; done >> /home/azureuser/xexe_run.log 2>&1 -git pull | while IFS= read -r line; do printf '%s %s\n' "$(date)" "$line"; done >> /home/azureuser/xexe_run.log 2>&1 +echo "Updating xexe project from git." +git checkout master +git pull # DWH-healthcheck -echo "Running DWH healthcheck..." | while IFS= read -r line; do printf '%s %s\n' "$(date)" "$line"; done >> /home/azureuser/xexe_run.log 2>&1 -poetry run xexe dwh-healthcheck | while IFS= read -r line; do printf '%s %s\n' "$(date)" "$line"; done >> /home/azureuser/xexe_run.log 2>&1 +echo "Running DWH healthcheck..." +poetry run xexe dwh-healthcheck if [ $? -ne 0 ]; then has_any_step_failed=1 - echo "Something went wrong when healthchecking DWH." | while IFS= read -r line; do printf '%s %s\n' "$(date)" "$line"; done >> /home/azureuser/xexe_run.log 2>&1 + echo "Something went wrong when healthchecking DWH." fi # xe healthcheck -echo "Running XE.com healthcheck..." | while IFS= read -r line; do printf '%s %s\n' "$(date)" "$line"; done >> /home/azureuser/xexe_run.log 2>&1 -poetry run xexe xe-healthcheck | while IFS= read -r line; do printf '%s %s\n' "$(date)" "$line"; done >> /home/azureuser/xexe_run.log 2>&1 +echo "Running XE.com healthcheck..." +poetry run xexe xe-healthcheck if [ $? -ne 0 ]; then has_any_step_failed=1 - echo "Something went wrong when healthchecking xe.com." | while IFS= read -r line; do printf '%s %s\n' "$(date)" "$line"; done >> /home/azureuser/xexe_run.log 2>&1 + echo "Something went wrong when healthchecking xe.com." fi # Define some options here. You might want to change this some day. @@ -47,11 +51,11 @@ start_date=$(date -d "yesterday" +"%Y-%m-%d") end_date=$(date -d "yesterday" +"%Y-%m-%d") # run the actual thing -echo "Getting rates from xe.com..." | while IFS= read -r line; do printf '%s %s\n' "$(date)" "$line"; done >> /home/azureuser/xexe_run.log 2>&1 -poetry run xexe get-rates --currencies "$currencies" --start-date "$start_date" --end-date "$end_date" --rates-source xe --output dwh --ignore-warnings | while IFS= read -r line; do printf '%s %s\n' "$(date)" "$line"; done >> /home/azureuser/xexe_run.log 2>&1 +echo "Getting rates from xe.com..." +poetry run xexe get-rates --currencies "$currencies" --start-date "$start_date" --end-date "$end_date" --rates-source xe --output dwh --ignore-warnings if [ $? -ne 0 ]; then has_any_step_failed=1 - echo "Something went wrong when getting rates." | while IFS= read -r line; do printf '%s %s\n' "$(date)" "$line"; done >> /home/azureuser/xexe_run.log 2>&1 + echo "Something went wrong when getting rates." fi # Check if any step failed and send a Slack message