Scheduling whitelisting and blacklisting

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

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

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

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