-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComicsPlus-previousDatesLoop.sh
More file actions
61 lines (48 loc) · 1.82 KB
/
Copy pathComicsPlus-previousDatesLoop.sh
File metadata and controls
61 lines (48 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
# James Staub, Nashville Public Library with significant assistance from JetBrains Junie
# ComicsPlus-previousDatesLoop.sh
# This script processes data for a range of dates by calling NashvilleMNPSDataWarehouseReport-ComicsPlus.sh
# for each date in the range.
# Display usage information if incorrect arguments are provided
if [ $# -lt 2 ]; then
echo "Usage: $0 <start_date> <stop_date> [-no-email] [-verbose]"
echo "Both dates must be in YYYY-MM-DD format"
echo "Example: $0 2026-05-01 2026-05-30"
exit 1
fi
start_date=$1
stop_date=$2
shift 2
extra_args=""
for arg in "$@"; do
extra_args="$extra_args $arg"
done
# Validate date formats
if ! date -d "$start_date" >/dev/null 2>&1; then
echo "Error: Invalid start date format. Please use YYYY-MM-DD."
exit 1
fi
if ! date -d "$stop_date" >/dev/null 2>&1; then
echo "Error: Invalid stop date format. Please use YYYY-MM-DD."
exit 1
fi
# Ensure start date is before or equal to stop date
if [[ $(date -d "$start_date" +%s) -gt $(date -d "$stop_date" +%s) ]]; then
echo "Error: Start date must be before or equal to stop date."
exit 1
fi
# Convert dates to seconds since epoch for comparison
start_seconds=$(date -d "$start_date" +%s)
stop_seconds=$(date -d "$stop_date" +%s)
current_seconds=$start_seconds
# Loop through all dates from start_date to stop_date
while [ $current_seconds -le $stop_seconds ]; do
# Format the current date as YYYY-MM-DD
current_date=$(date -d "@$current_seconds" +%Y-%m-%d)
echo "Processing date: $current_date"
# Run the script with the date as an argument
./NashvilleMNPSDataWarehouseReport-ComicsPlus.sh "$current_date" $extra_args 2>&1 >/dev/null
# Move to the next day (add 86400 seconds = 24 hours)
current_seconds=$((current_seconds + 86400))
done
echo "Processing complete for date range: $start_date to $stop_date"