# Activate group with cron

**URL:** <https://discourse.pi-hole.net/t/activate-group-with-cron/32660>\
**Category:** Community Help\
**Tags:** v5-0\
**Created:** [May 16, 2020, 11:18pm UTC](https://discourse.pi-hole.net/t/activate-group-with-cron/32660 "2020-05-16T23:18:46Z")\
**Posts on this page:** 1\
**Showing post:** 16

<div class="post-metadata">

**Author:** ![piDiddy](https://discourse-cdn.pi-hole.net/letter_avatar_proxy/v4/letter/p/bbce88/32.png) [@piDiddy](https://discourse.pi-hole.net/u/piDiddy)\
**Post date:** [October 17, 2020, 1:01am UTC](https://discourse.pi-hole.net/t/activate-group-with-cron/32660/16 "2020-10-17T01:01:50Z")

</div>

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:

```auto
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`:

```auto
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.

---

_[View the full topic](https://discourse.pi-hole.net/t/activate-group-with-cron/32660)._
