#!/bin/bash
if [[ $(cat /etc/trueuserowners | wc -l) -le 2 ]]; then
echo "OK: no users."
exit 0
fi
MINSIZE=10
MAXSIZE=5000
EXIMSTATSDB='/var/cpanel/eximstats_db.sqlite3'
EXIMSTATSDBNAME='eximstats_db.sqlite3'
SLEEP_TIME=840 #14 min
suffix="";
jetbackup_pid="$(sudo /usr/bin/pgrep -cf jetbackup5d-backup)"
fstrim_pid="$(sudo /usr/bin/pgrep -x fstrim)"
if [ "$jetbackup_pid" -gt 1 ] || [ -n "$fstrim_pid" ]; then
cedi_pid="$(pgrep -f '&& sudo /root/amscripts/check_eximstats_db_integrity.sh')"
if [ -z "$cedi_pid" ]; then
nohup sh -c "sleep $SLEEP_TIME && sudo /root/amscripts/check_eximstats_db_integrity.sh" > /dev/null 2>&1 &
fi
suffix="[Preload Scheduled]";
fi
if [ ! -f "$EXIMSTATSDB" ]; then
echo "CRITICAL: $EXIMSTATSDB missing. $suffix"
exit 2
elif [ "$(sudo /root/amscripts/check_eximstats_db_integrity.sh)" != "ok" ]; then
echo "CRITICAL: $EXIMSTATSDB is corrupt. $suffix"
exit 2
elif [ "$(du -m $EXIMSTATSDB | cut -f 1)" -lt "$MINSIZE" ]; then
echo "WARNING: Size of $EXIMSTATSDBNAME is too small. Please check. $suffix"
exit 1
elif [ "$(du -m $EXIMSTATSDB | cut -f 1)" -gt "$MAXSIZE" ]; then
echo "WARNING: Size of $EXIMSTATSDBNAME is too large. Please check. $suffix"
exit 1
else
echo "OK: $EXIMSTATSDBNAME is operational. $suffix"
exit 0
fi