2015-12-06 14:55:50 +01:00
#!/usr/bin/env bash
2016-01-30 21:12:40 +01:00
# Pi-hole: A black hole for Internet advertisements
2017-02-22 18:55:20 +01:00
# (c) 2017 Pi-hole, LLC (https://pi-hole.net)
# Network-wide ad blocking via your own hardware.
#
2017-04-17 21:25:15 +02:00
# Flushes Pi-hole's log file
2015-12-06 14:55:50 +01:00
#
2017-02-22 18:55:20 +01:00
# This file is copyright under the latest version of the EUPL.
# Please see LICENSE file for your rights under this license.
2017-06-21 13:49:05 +02:00
colfile = "/opt/pihole/COL_TABLE"
source ${ colfile }
2017-05-17 12:54:43 +02:00
if [ [ " $@ " != *"quiet" * ] ] ; then
2017-06-21 13:49:05 +02:00
echo -ne " ${ INFO } Flushing /var/log/pihole.log ... "
2017-05-17 12:54:43 +02:00
fi
2017-05-17 12:44:35 +02:00
if [ [ " $@ " = = *"once" * ] ] ; then
# Nightly logrotation
if command -v /usr/sbin/logrotate >/dev/null; then
# Logrotate once
/usr/sbin/logrotate --force /etc/pihole/logrotate
else
# Copy pihole.log over to pihole.log.1
# and empty out pihole.log
# Note that moving the file is not an option, as
# dnsmasq would happily continue writing into the
# moved file (it will have the same file handler)
cp /var/log/pihole.log /var/log/pihole.log.1
echo " " > /var/log/pihole.log
fi
2017-01-12 20:39:25 +01:00
else
2017-05-17 12:44:35 +02:00
# Manual flushing
if command -v /usr/sbin/logrotate >/dev/null; then
# Logrotate twice to move all data out of sight of FTL
/usr/sbin/logrotate --force /etc/pihole/logrotate; sleep 3
/usr/sbin/logrotate --force /etc/pihole/logrotate
else
# Flush both pihole.log and pihole.log.1 (if existing)
echo " " > /var/log/pihole.log
if [ -f /var/log/pihole.log.1 ] ; then
echo " " > /var/log/pihole.log.1
fi
2017-04-17 21:25:15 +02:00
fi
2018-01-21 11:54:49 +01:00
# Delete most recent 24 hours from FTL's database
2018-01-21 13:48:13 +01:00
deleted = $( sqlite3 /etc/pihole/pihole-FTL.db "DELETE FROM queries WHERE timestamp >= strftime('%s','now')-86400; select changes() from queries limit 1" )
2017-05-17 12:54:43 +02:00
fi
if [ [ " $@ " != *"quiet" * ] ] ; then
2017-06-21 13:49:05 +02:00
echo -e " ${ OVER } ${ TICK } Flushed /var/log/pihole.log "
2018-01-21 13:48:13 +01:00
echo -e " ${ TICK } Deleted ${ deleted } queries from database "
2017-01-12 20:39:25 +01:00
fi