Activate group with cron

Thank you all for the info. I used the above to enable disable a group based on time. For those looking for complete steps:
Configuration

  1. Create a group: Group Management>Groups>Add. E.g. "School"
  2. Add clients to the Group Configuration: Group Management>Clients>Select Client>Add.
  3. Set the client to the newly created group in Group Assignment (i.e. "School"). Do not put it into the Default group.
  4. Add blacklist of domains: Group Management>Domains:Domain>Add to Blacklist. E.g. To block ALL of youtube, type in: youtube.com and select Add domain as wildcard.
  5. Set the blacklist to the group: Under List of Entries set the Group Assignment to the new group (i.e. "School")
  6. Test it out:
    1. Enable the Group: Under Group Management>Groups, the Status should be Enabled.
    2. On the target host, open a browser in private mode and go to the blacklisted site. Confirm it is blocked.
    3. Disable the Group, and confirm that the target machine can visit the blacklisted site.
  7. You can do this manually whenever needed.

Automatic Scheduling
To set enable the block on regular intervals (e.g. 8am-2pm M-F)

  1. ssh to your pihole
  2. Edit the crontab file: crontab -e
  3. Add the following lines:
0 8 * * 1-5 sudo sqlite3 /etc/pihole/gravity.db "update 'group' set enabled = 1 where name = '<name of group>'" >> /tmp/pihole_group.log 2>&1
0 14 * * 1-5 sudo sqlite3 /etc/pihole/gravity.db "update 'group' set enabled = 0 where name = '<name of group>'" >> /tmp/pihole_group.log 2>&1

E.g. for group name School:

0 8 * * 1-5 sudo sqlite3 /etc/pihole/gravity.db "update 'group' set enabled = 1 where name = 'School'" >> /tmp/pihole_group.log 2>&1
0 14 * * 1-5 sudo sqlite3 /etc/pihole/gravity.db "update 'group' set enabled = 0 where name = 'School'" >> /tmp/pihole_group.log 2>&1

If you have any issues, check /tmp/pihole_group.log. If all is running correctly, the log file will be empty.

5 Likes