Schedule a group in group management

Hi there,

I’m using pi-hole from version 4.x / beta 5.0 and now on 5.0, the group management is perfect, exactly what was missing in the previous version(s)

From al the groups, there are two that I enable /disable on weekendhours. Is there a way that I can schedule this in any way?

I didn’ find this on a search, but maybe it’s my searchskill :wink:

example: group name = testgroup

create script /home/pi/modify_testgroup.sh
chmod +x /home/pi/modify_testgroup.sh

dayofweek="$(date +%w)"
group="testgroup"

# Monday (see https://stackoverflow.com/questions/18919151/crontab-day-of-the-week-syntax)
if [ ${dayofweek} = "1" ]; then 
	enabled=1
# saturday
elif [ ${dayofweek} = "6" ]; then 
	enabled=0
else
	exit
fi

gravitydb="/etc/pihole/gravity.db"
groupid=$(sqlite3 ${gravitydb} "SELECT id FROM 'group' WHERE name = '${group}';")
sudo sqlite3 ${gravitydb} "update 'group' set enabled = '${enabled}' WHERE id = '${groupid}';"

pihole restartdns reload-lists

create cron file /etc/cron.d/modify_testgroup

# enable testgroup on Monday 00:01
1 0    * * 1   root    PATH="$PATH:/home/pi/" /home/pi/modify_testgroup.sh
# disable testgroup on Saturday 00:01
1 0    * * 6   root    PATH="$PATH:/home/pi/" /home/pi/modify_testgroup.sh

last extra blank line in cron file recommended, I found some cron entries don't work if the extra linefeed is missing.

1 Like

You have to add
pihole restartdns reload-lists

correct, edited the above script, thanks.

Thanks for your reply, I’ll let you know if things works out..

Attention crontab use sh if your script is bash use bash for exec.

For debug, install postfix for read the error messages because no info in syslog.

It works like a charm, thanks for your help. :wink:
(Pihole runs on a linux mint virtual machine, so postfix allready in place)