#!/bin/bash # Title: automated-job-check.sh # Description: Determine if an automated job should be run # Script to execute: See 'if statement' for dynamically selecting an environment script="/automation/scripts/automated-job.py" # Log file log_file="/var/log/automation/automated-job-check_$(date +%Y%m).log" echo "==== Log Started: $(date) ====" >> ${log_file} # If today is Tuesday AND today is >=1 and <=21(1st,2nd,3rd Tue) if [[ "$(date '+%a')" == "Tue" ]] && [[ $(date +%-d) -ge 1 ]]; then # First Tue: Development Environment if [[ $(date +%-d) -le 7 ]]; then echo ">> OK: Today is the first Tue of the Month; execute script(${script} --group all_dev)." >> ${log_file} ${script} --group all_dev 2>&1 >> ${log_file} # Second Tue: Test Environment elif [[ $(date +%-d) -le 14 ]]; then echo ">> OK: Today is the second Tue of the Month; execute script(${script} --group all_test)." >> ${log_file} ${script} --group all_test 2>&1 >> ${log_file} # Third Tue: Production Environment elif [[ $(date +%-d) -le 21 ]]; then echo ">> OK: Today is the third Tue of the Month; execute script(${script} --group all_prod)." >> ${log_file} ${script} --group all_prod 2>&1 >> ${log_file} else echo ">> NO-EXEC: Today is NOT the first,second, or third Tue of the Month. Will NOT execute script(${script})." >> ${log_file} fi else echo ">> NO-EXEC: Today is NOT the first,second, or third Tue of the Month. Will NOT execute script(${script})." >> ${log_file} fi echo -e "==== Log Ended: $(date) ====\n" >> ${log_file}