-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathweekly.sh
More file actions
executable file
·78 lines (78 loc) · 2.97 KB
/
weekly.sh
File metadata and controls
executable file
·78 lines (78 loc) · 2.97 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
SECONDS=0
# ---------------------------------------------------
YEAR=`date '+%Y'`
MONTH=`date '+%m'`
DAY=`date '+%d'`
WEEK=`date '+%U'`
# ---------------------------------------------------
# source the configuration file
# it must be edited and copied as ".BirdNET-BarChart" to you home directory
CONFIG_FILE=${HOME}/.BirdNET-BarChart
if [ -f "${CONFIG_FILE}" ]; then
source ${CONFIG_FILE}
else
echo " "
echo "${CONFIG_FILE} does not exist."
echo "Run the config.sh script to create."
echo " "
exit 1
fi
# ---------------------------------------------------
function calculatePercentageUsed {
ROOTDIR=`echo ${BARCHART_HOME} | cut -d '/' -f 2`
if mountpoint -q /${ROOTDIR}; then
echo `df -h | grep -oP "\d{1,2}% \/${ROOTDIR}$" | grep -oP "\d{1,2}"`
else
echo "$(df -h | grep -oP '\d{1,2}% \/$' | grep -oP '\d{1,2}')"
fi
}
# ---------------------------------------------------
{
# update the species_list.txt for this location and week of the year
pushd ${ANALYZER_HOME}
source ${ANALYZER_HOME}/venv-birdnet/bin/activate
python3 -m birdnet_analyzer.species --lat ${LAT} --lon ${LON} --week ${WEEK} ${BARCHART_HOME}/work/species_list.txt
popd
# remove the frequent false positives
grep -v -f ${BARCHART_HOME}/work/species_blacklist.txt ${BARCHART_HOME}/work/species_list.txt > /tmp/t.txt && cat /tmp/t.txt > ${BARCHART_HOME}/work/species_list.txt
# check how full storage is getting at /
PERCENT_STORAGE_USED=$(calculatePercentageUsed)
echo "${PERCENT_STORAGE_USED} percent used"
if [ ${PERCENT_STORAGE_USED} -ge ${PERCENT_STORAGE_ALLOWED} ]; then
# compress all logs older than today
find ${BARCHART_HOME}/logs -not -name "*.md" -mtime +1 -exec gzip -v {} \;
# still too much?
PERCENT_STORAGE_USED=$(calculatePercentageUsed)
echo "${PERCENT_STORAGE_USED} percent used"
if [ ${PERCENT_STORAGE_USED} -ge ${PERCENT_STORAGE_ALLOWED} ]; then
# delete all logs older than a week
find ${BARCHART_HOME}/logs -mtime +7 -name "*.gz" -not -name "*.md" -delete -print
# still too much?
PERCENT_STORAGE_USED=$(calculatePercentageUsed)
echo "${PERCENT_STORAGE_USED} percent used"
# start 90 days out
COUNTDOWN=90
while [ ${PERCENT_STORAGE_USED} -ge ${PERCENT_STORAGE_ALLOWED} ]; do
# delete all sound samples older than COUNTDOWN days
find ${BARCHART_HOME}/work -mtime +${COUNTDOWN} -name "*.wav.gz" -delete -print
# one day closer
((COUNTDOWN--))
if [ ${COUNTDOWN} -ge 0 ]; then
echo "${COUNTDOWN} days out"
else
ssmtp -vvv dacracot@gmail.com < ${BARCHART_HOME}/util/storageFailure.txt
exit 1
fi
# still too much?
PERCENT_STORAGE_USED=$(calculatePercentageUsed)
echo "${PERCENT_STORAGE_USED} percent used"
done
fi
fi
# delete any leftover empty directories
find ${BARCHART_HOME}/work -empty -type d -delete
# how long did it take
DURATION=$SECONDS
echo "$(($DURATION / 60)) minutes and $(($DURATION % 60)) seconds elapsed."
} >> ${BARCHART_HOME}/logs/${YEAR}-${MONTH}-${DAY}-weekly.out 2>> ${BARCHART_HOME}/logs/${YEAR}-${MONTH}-${DAY}-weekly.err