How to find missing files between specific date range?
# presuming that the files are e. g. template-2017-07-01-16:
# To test a given date
for file in template-2017-07-01-{00..23}; do
if ! [[ -f "$file" ]]; then
echo "$file is missing"
fi
done
# To test a given year
year=2017
for month in seq -w 1 12; do
dim=$( cal $( date -d "$year-$month-01" "+%m %Y" | awk 'NF { days=$NF} END {print days}' )
for day in $(seq -w 1 $dim); do
for file in template-${year}-${month}-${day}-{00..23}; do
if ! [[ -f "$file" ]]; then
echo "$file is missing"
fi
done
done
done
On a GNU system:
#! /bin/bash -
ret=0
start=${1?} end=${2?}
t1=$(date -d "$start" +%s) t2=$(date -d "$end" +%s)
for ((t = t1; t < t2; t += 60*60)); do
printf -v file '%(%F-%H)T' "$t"
if [ ! -e "$file" ]; then
printf >&2 '"%s" not found\n' "$file"
ret=1
fi
done
exit "$ret"
Note that on the day of the switch to winter time (in timezones that implement daylight saving), you may get an error message twice if a file is missing for the hour of the switch. Fix $TZ
to UTC0 if you want 24 hours per day for every day (for instance, if whatever creates those files uses UTC time instead of local time).
What about command like below:
grep -Fvf <(find * -type f \( -name "2017-07-02-00" $(printf " -o -name %s" 2017-07-02-{01..23}) \)) \
<(printf "%s\n" 2017-07-02-{00..23})
ls
2017-07-02-01 2017-07-02-06 2017-07-02-08 2017-07-02-14 2017-07-02-19
2017-07-02-04 2017-07-02-07 2017-07-02-11 2017-07-02-15 2017-07-02-22
The output after command ran:
2017-07-02-00
2017-07-02-02
2017-07-02-03
2017-07-02-05
2017-07-02-09
2017-07-02-10
2017-07-02-12
2017-07-02-13
2017-07-02-16
2017-07-02-17
2017-07-02-18
2017-07-02-20
2017-07-02-21
2017-07-02-23
Above we are generating all possibilities of 24 files using printf
and pass it to find
its -name
parameter which printf
also helping her, then with grep
command we are printing those files are exist in our pattern but find
didn't find them.