#!/usr/bin/env bash # Cron entry point. It considers every cycle at least three days old in the # current and previous month, so late RCM delivery is retried automatically. set -euo pipefail project_root=/home/tanpv/Progs/CLI/Dr raw_root=/home/tanpv/Data/562_VNU/0.25_VN/Operational/monthly log_root="$project_root/logs" lock_file="$project_root/.operational_auto.lock" mkdir -p "$log_root" exec 9>"$lock_file" flock -n 9 || exit 0 echo "$(date -Is) status=SCAN_STARTED" now_epoch=$(date +%s) for offset in -1 0; do ym=$(date -d "$(date +%Y-%m-15) $offset month" +%Y-%m) year=${ym%-*} month=${ym#*-} for spec in '01 1 01' '06 2 02' '11 3 03' '16 4 04' '21 5 05' '26 6 06'; do read -r day cycle member <<<"$spec" init_epoch=$(date -d "$year-$month-$day +3 days" +%s) (( now_epoch >= init_epoch )) || continue output="$project_root/outputs/Ope/$year/$month/$day" [[ -f "$output/SUCCESS" ]] && continue regcm="$raw_root/$year/$month/RegCM_${member}.nc" clwrf="$raw_root/$year/$month/clWRF_${member}.nc" if [[ ! -s "$regcm" || ! -s "$clwrf" ]]; then echo "$(date -Is) init=$year-$month-$day status=WAITING_FOR_INPUT" continue fi marker="$output/SUBMITTED" if [[ -s "$marker" ]]; then job_id=$(awk 'NR==1 {print $1}' "$marker") if [[ "$job_id" =~ ^[0-9]+$ ]] && squeue -h -j "$job_id" 2>/dev/null | grep -q .; then echo "$(date -Is) init=$year-$month-$day status=ALREADY_QUEUED job=$job_id" continue fi fi "$project_root/remap_one_cycle.sh" "$year" "$month" "$day" mkdir -p "$output" submission=$(sbatch --parsable "$project_root/submit_operational_cycle.sbatch" "$year" "$month" "$cycle") job_id=${submission%%;*} printf '%s\n%s\n' "$job_id" "$(date -Is)" > "$marker" echo "$(date -Is) init=$year-$month-$day status=SUBMITTED job=$job_id" done done echo "$(date -Is) status=SCAN_FINISHED"