setting up Pi-Hole + PiVPN + read/write root access for adding youtube script

I have DietPi with Pi-Hole (with Unbound) and PiVPN (Wireguard) on raspberry pi 1B. My router handles port forwarding & manages DHCP which assigns pi the static ip. Everything was working and stable until I learned about the script to block most youtube ads https://gitlab.com/grublets/youtube-updater-for-pi-hole .

I’d like to run this script as root in my Pi-hole and cron per the instructions but I’m having a hard time accomplishing the first step which is simply download the script to /usr/local/bin.

I tried file server ProFTPD & Samba which get me to specified directories (picture/music/…etc) and I can’t access others. With OpenSSH I can do SFTP/SCP but the switch to OpenSSH server breaks my access to the pi-hole admin interface and my internet access.

I’m new to this & I suspect I’m making a simple mistake somewhere. My goal is read/write ftp or ssh access to dietpi so I can transfer the script and run it. Once I have that working the plan is to add a cron entry for script updates.

Any advice would be appreciated.

Hi,

you simply can download the file directly to your DietPi device by doing dollowing

wget https://gitlab.com/grublets/youtube-updater-for-pi-hole/-/raw/master/youtube.update.sh



I tried file server ProFTPD & Samba which get me to specified directories (picture/music/…etc) and I can’t access others.

This is correct and working as expected because /mnt/dietpi_userdata is defined as root directory for the file services. On our online docs, we describe how to change the destination directory for both FPT as well as Samba File Servers Options - DietPi.com Docs

With OpenSSH I can do SFTP/SCP

There is no need to fully switch to OpenSSH server. You can simple install OpenSSH client (ID 0) to get SFTP/SCP working. However, installation of OpenSSH Server should not break other services.

Another option is to simple copy/past the code. It’s not a long script and you could do simple nano /usr/local/bin/youtube.update.sh and add content of the script https://gitlab.com/grublets/youtube-updater-for-pi-hole/-/raw/master/youtube.update.sh

thanks for the help. I went with your last suggestion of simple copy/paste and created the script directly in cron.minutely so it would run every minute for constant updates as recommended by the script author. Dietpi+pihole+pivpn has brought new life to my old rpi. Thank you.

pls have a look if the script is executed correctly. usually there is no ending like .sh allowed. As well keep an eye on your system as restarting DNS every minute could overload it.

sorry that my question is so basic but how would I confirm? I’m guessing via log, if so where do I find that?
also how frequently would you recommend I run it? hourly? daily?
thanks again

If I understood the code correctly, a log file should be written to /var/log/pihole.log as well as blocked hosts are stored in /etc/hosts.youtube. Both files should be growing. As well you can check CRON log journalctl -u cron.service

not sure what is a good time frame as I don’t have such a script running. I just have seen the comments on Git about such issues https://gitlab.com/grublets/youtube-updater-for-pi-hole/-/issues

looks like the script is not running as /var/log/pihole.log and /etc/hosts.youtube are not growing and are both actually 0 bytes.
I did change minutely scripts to run every 5mins. I’ll follow the script instructions again to be sure I didn’t miss anything. Ads are being blocked so I’m happy just not youtube while I figure it out.
Thanks again

can you share ls -la /etc/cron.minutely/

total 16
drwxr-xr-x 2 root root 4096 Feb 19 20:00 .
drwxr-xr-x 79 root root 4096 Feb 19 18:59 …
-rw-r–r-- 1 root root 163 Jan 18 16:17 readme.txt
-rwxr-xr-x 1 root root 1434 Feb 18 17:18 youtube.update

I did take out the .sh

Please remove the dot from the file name. Cron (respectively run-parts) only executes files with pure alphanumerical/dash/underscore names: https://manpages.debian.org/buster/debianutils/run-parts.8.en.html#DESCRIPTION

I changed the name and ls -la /etc/cron.minutely/ outputs:
total 16
drwxr-xr-x 2 root root 4096 Feb 20 19:55 .
drwxr-xr-x 79 root root 4096 Feb 20 01:31 …
-rw-r–r-- 1 root root 163 Jan 18 16:17 readme.txt
-rwxr-xr-x 1 root root 1436 Feb 20 19:55 youtubeupdate

/var/log/pihole.log and /etc/hosts.youtube are still not growing and are both 0 bytes

my log file shows:
CRON[23645]: (root) CMD (cd / && run-parts --report /etc/cron.minutely)
at the correct times

I still get youtube ads I’m not sure but I think they might be reduced. Script author does say some ads will get through. If I’m reading the log correctly it appears the script is running at intervals specified.

Thanks for the help & thanks for DietPi its great.

/var/log/pihole.log is not used when installing Pi-hole through dietpi-software. You could enable that query log via pihole -l on but it mostly doubles with the separate query log that is anyway done to the database and what the log in the web UI is based on. I.e. you should be able to see blocked YouTube ads in the query log section of the web interface.

/etc/hosts.youtube would not have an effect when it’s empty, would it? :thinking:

… ah I had a look into the script and it parses /var/log/pihole.log indeed. Then you need to:

  1. Disable DietPi-RAMlog (if currently enabled): dietpi-software uninstall 103
  2. Reboot: reboot
  3. Enable Pi-hole file query logging: pihole -l on

Could be actually an enhancement to the script if it would query the SQLite database instead of the plain text log file.

ahh indeed overlooked that it require the PiHole log file

MichaIng
Well the script was updated last time 9 month ago. Not sure if it is still maintained :slight_smile: