# Scheduling whitelisting and blacklisting

**URL:** https://discourse.pi-hole.net/t/scheduling-whitelisting-and-blacklisting/14001
**Category:** Customizing Pi-hole
**Created:** [October 27, 2018, 1:45pm UTC](https://discourse.pi-hole.net/t/scheduling-whitelisting-and-blacklisting/14001 "2018-10-27T13:45:47Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![wonshu](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/wonshu/32/5353_2.png) [@wonshu](https://discourse.pi-hole.net/u/wonshu)
#### Post date: [October 27, 2018, 1:45pm UTC](https://discourse.pi-hole.net/t/scheduling-whitelisting-and-blacklisting/14001/1 "2018-10-27T13:45:47Z")

</div>

Hi there,

so, today I had the idea to use a pi-hole in our network to block YouTube (yes, the kid watches too much and I'm tired of the fights). So this is what I thought:

Idea:  
What if I can get Pihole to flip whitelist or blacklist of youtube.com at quasi random intervals so when our kid uses a device it may or may not work and I can claim that I have no idea why. If it's alway off, then the kid knows that I've been tampering with something.

Solution:  
Write a bashscript 1 "whitelist\_youtube.sh" in the root account that looks like this:  
#!/bin/bash  
usr/local/bin/pihole -w youtube.com  
sleep 20 seconds  
usr/local/bin/pihole -w www.youtube.com  
usr/local/bin/pihole updateGravity

and write a bashscript 2 "blacklist\_youtube.sh" in the root account that looks like this:  
#!/bin/bash  
usr/local/bin/pihole -b youtube.com  
sleep 20 seconds  
usr/local/bin/pihole -b www.youtube.com  
usr/local/bin/pihole updateGravity

Then I create cronjobs in the root account to call these scripts at intervals that don't overlap much. I though which are the two lowest prime numbers that have the least occurrences of falling onto the same minute, so that there are as little hickups as possible when cron runs those commands at the same time. I came up with (and I'm no mathematician let alone a good coder) this:

\*/31 \* \* \* \* /root/scripts/whitelist\_youtube.sh

\*/47 \* \* \* \* /root/scripts/blacklist\_youtube.sh

My question:  
When testing this whole thing with shorter time intervals (I hate waiting obviously) it would only work when I issue the usr/local/bin/pihole updateGravity command in the script.

Is this the expected behaviour or shouldn't pihole update the blocking with just using pihole -w or pihole -b? I was expecting it to, but it didn't block or unblock without updating gravity.

Am I doing something wrong? Is there a better way to achieve what I want to do?

Thanks and best  
Hans

---

<div class="post-metadata">

### Author: ![Djn](https://discourse-cdn.pi-hole.net/letter_avatar_proxy/v4/letter/d/9f8e36/32.png) [@Djn](https://discourse.pi-hole.net/u/Djn)
#### Post date: [October 27, 2018, 10:43pm UTC](https://discourse.pi-hole.net/t/scheduling-whitelisting-and-blacklisting/14001/2 "2018-10-27T22:43:31Z")

</div>

This is what I have setup  
block.sh  
#!/bin/bash  
/usr/local/bin/pihole -b cloudconfig.googleapis.com i.ytimg.com youtube.com  
sleep 5  
/usr/local/bin/pihole --wild googlevideo.com l.google.com youtube.com  
sleep 5  
/usr/local/bin/pihole -g  
sleep 60  
/usr/local/bin/pihole restartdns  
Then unblock.sh

#!/bin/bash  
/usr/local/bin/pihole -b -d cloudconfig.googleapis.com i.ytimg.com youtube.com  
sleep 2  
/usr/local/bin/pihole --wild -d googlevideo.com l.google.com youtube.com  
sleep 5  
/usr/local/bin/pihole -g  
sleep 60  
/usr/local/bin/pihole restartdns

-b for domains --wild for wildcards the other domains block the iphone app too  
I had to add restartdns or sometimes the script wouldnt work

---

<div class="post-metadata">

### Author: ![wonshu](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/wonshu/32/5353_2.png) [@wonshu](https://discourse.pi-hole.net/u/wonshu)
#### Post date: [October 30, 2018, 8:11pm UTC](https://discourse.pi-hole.net/t/scheduling-whitelisting-and-blacklisting/14001/3 "2018-10-30T20:11:11Z")

</div>

Ah, so you had the same idea. Nice!

Of course your solution is much more intricate and I will remember to come to that when the time is right, for now, we're good with having the random youtube blocker on. Works great, but I reduced the interval time to 5 and 7 minutes....

Thanks!  
Hans

---

<div class="post-metadata">

### Author: ![sevufajiji](https://discourse-cdn.pi-hole.net/letter_avatar_proxy/v4/letter/s/839c29/32.png) [@sevufajiji](https://discourse.pi-hole.net/u/sevufajiji)
#### Post date: [March 5, 2019, 7:20am UTC](https://discourse.pi-hole.net/t/scheduling-whitelisting-and-blacklisting/14001/4 "2019-03-05T07:20:36Z")

</div>

Nice idea, is this also possible when you going to a specific domain and start a script as this?
