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